dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxSumLCM ( n ) { for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { max_sum += i ; if ( n / i != i ) max_sum += ( n / i ) ; } } return max_sum ; } let n = 2 ; document . write ( maxSumLCM ( n ) + " " ) ;

Accumulator variables: i, max_sum
Iterator variables: i
Javascript program:
function findMaxValue ( ) { let res = 2 ; let fact = 2 ; while ( true ) { if ( fact < 0 fact > 9223372036854775807 ) break ; res ++ ; fact = fact * res ; } return res - 1 ; } document . write ( " " + " " + findMaxValue ( ) ) ;

Accumulator variables: res
Javascript program:
function func ( a , k ) { for ( let i = 0 ; i < a . length ; i ++ ) if ( a [ i ] % k == 0 ) return true ; return false ; } let a = [ 14 , 27 , 38 , 76 , 84 ] ; var k = 19 ; let res = func ( a , k ) ; document . write ( res ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function tidyNum ( str1 , len ) { var str = str1 . split ( ' ' ) ; for ( i = len - 2 ; i >= 0 ; i -- ) { if ( str [ i ] > str [ i + 1 ] ) { str [ i ] -- ; for ( j = i + 1 ; j < len ; j ++ ) str [ j ] = ' ' ; } } return str . join ( " " ) ; } var str = " " ; var len = str . length ; document . write ( tidyNum ( str , len ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findCount ( m , n ) { let num1 = 0 ; for ( let i = 0 ; i < m ; i ++ ) num1 = ( num1 * 10 ) + 9 ; let num2 = 0 ; for ( let i = 0 ; i < ( m - 1 ) ; i ++ ) num2 = ( num2 * 10 ) + 9 ; return ( ( num1 / n ) - ( num2 / n ) ) ; } let m = 2 ; n = 6 ; document . write ( findCount ( m , n ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findNthEvenDigitNumber ( n ) { let count = 0 ; for ( let i = 0 ; ; i ++ ) { let curr = i ; let isCurrEvenDigit = true ; while ( curr != 0 ) { if ( curr % 10 == 1 curr % 10 == 3 curr % 10 == 5 curr % 10 == 7 curr % 10 == 9 ) isCurrEvenDigit = false ; curr = Math . floor ( curr / 10 ) ; } if ( isCurrEvenDigit === true ) count ++ ; if ( count === n ) return i ; } } document . write ( findNthEvenDigitNumber ( 2 ) + " " ) ; document . write ( findNthEvenDigitNumber ( 10 ) + " " ) ;

Accumulator variables: count, i
Iterator variables: i
Boolean variables: isCurrEvenDigit
Javascript program:
function findNthEvenDigitNumber ( n ) { if ( n == 1 ) { return 0 ; } let v = [ ] ; n = n - 1 ; while ( n > 0 ) { v . push ( n % 5 ) ; n = Math . floor ( n / 5 ) ; } let result = 0 ; for ( let i = v . length - 1 ; i >= 0 ; i -- ) { result = result * 10 ; result = result + v [ i ] ; } return 2 * result ; } document . write ( findNthEvenDigitNumber ( 2 ) + " " ) ; document . write ( findNthEvenDigitNumber ( 10 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findIndex ( n ) { if ( n <= 1 ) return n ; let a = 0 , b = 1 , c = 1 ; let res = 1 ; while ( c < n ) { c = a + b ; res ++ ; a = b ; b = c ; } return res ; } let result = findIndex ( 21 ) ; document . write ( result ) ;

Accumulator variables: res
Javascript program:
var m2 , d2 ; function isLeap ( y ) { if ( y % 100 != 0 && y % 4 == 0 y % 400 == 0 ) return true ; return false ; } function offsetDays ( d , m , y ) { var offset = d ; if ( m - 1 == 11 ) offset += 335 ; if ( m - 1 == 10 ) offset += 304 ; if ( m - 1 == 9 ) offset += 273 ; if ( m - 1 == 8 ) offset += 243 ; if ( m - 1 == 7 ) offset += 212 ; if ( m - 1 == 6 ) offset += 181 ; if ( m - 1 == 5 ) offset += 151 ; if ( m - 1 == 4 ) offset += 120 ; if ( m - 1 == 3 ) offset += 90 ; if ( m - 1 == 2 ) offset += 59 ; if ( m - 1 == 1 ) offset += 31 ; if ( isLeap ( y ) && m > 2 ) offset += 1 ; return offset ; } function revoffsetDays ( offset , y ) { var month = [ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; if ( isLeap ( y ) ) month [ 2 ] = 29 ; var i ; for ( i = 1 ; i <= 12 ; i ++ ) { if ( offset <= month [ i ] ) break ; offset = offset - month [ i ] ; } d2 = offset ; m2 = i ; } function addDays ( d1 , m1 , y1 , x ) { var offset1 = offsetDays ( d1 , m1 , y1 ) ; var remDays = isLeap ( y1 ) ? ( 366 - offset1 ) : ( 365 - offset1 ) ; var y2 , offset2 = 0 ; if ( x <= remDays ) { y2 = y1 ; offset2 = offset1 + x ; } else { x -= remDays ; y2 = y1 + 1 ; var y2days = isLeap ( y2 ) ? 366 : 365 ; while ( x >= y2days ) { x -= y2days ; y2 ++ ; y2days = isLeap ( y2 ) ? 366 : 365 ; } offset2 = x ; } revoffsetDays ( offset2 , y2 ) ; document . write ( " " + d2 + " " + m2 + " " + y2 ) ; } var d = 14 , m = 3 , y = 2015 ; var x = 366 ; addDays ( d , m , y , x ) ;

Index/key variables: i
Accumulator variables: i, offset, x, y2
Iterator variables: i
Javascript program:
function divisorSum ( N , K ) { let sum = 0 ; for ( let i = 2 ; i <= Math . ceil ( Math . sqrt ( N ) ) ; i ++ ) if ( N % i == 0 ) sum += ( i + parseInt ( N / i , 10 ) ) ; return sum ; } function isPrime ( n ) { if ( n == 1 n == 0 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function isHyperPerfect ( N , K ) { let sum = divisorSum ( N , K ) ; if ( ( 1 + K * ( sum ) ) == N ) return true ; else return false ; } let N1 = 1570153 , K1 = 12 ; let N2 = 321 , K2 = 3 ; if ( isHyperPerfect ( N1 , K1 ) ) document . write ( N1 + " " + K1 + " " + " " ) ; else document . write ( N1 + " " + K1 + " " + " " ) ; if ( isHyperPerfect ( N2 , K2 ) ) document . write ( N2 + " " + K2 + " " + " " ) ; else document . write ( N2 + " " + K2 + " " + " " ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function printWellOrdered ( number , x , k ) { if ( k == 0 ) { document . write ( number + " " ) ; return ; } for ( let i = ( x + 1 ) ; i < 10 ; i ++ ) printWellOrdered ( number * 10 + i , i , k - 1 ) ; } function generateWellOrdered ( k ) { printWellOrdered ( 0 , 0 , k ) ; } let k = 3 ; generateWellOrdered ( k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function numberOf2sinRange ( n ) { var s = " " ; for ( var i = 0 ; i < n + 1 ; i ++ ) s += i . toString ( ) ; var count = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { count ++ ; } } return count ; } var n = 30 ; document . write ( numberOf2sinRange ( n ) ) ;

Accumulator variables: count, i, s
Iterator variables: i
Javascript program:
function count2sinRangeAtDigit ( number , d ) { var powerOf10 = parseInt ( Math . pow ( 10 , d ) ) ; var nextPowerOf10 = powerOf10 * 10 ; var right = number % powerOf10 ; var roundDown = number - number % nextPowerOf10 ; var roundup = roundDown + nextPowerOf10 ; var digit = parseInt ( number / powerOf10 ) % 10 ; if ( digit < 2 ) { return roundDown / 10 ; } if ( digit == 2 ) { return roundDown / 10 + right + 1 ; } return roundup / 10 ; } function numberOf2sinRange ( number ) { var convert ; convert = number . toString ( ) ; var s = convert ; var len = s . length ; var count = 0 ; for ( digit = 0 ; digit < len ; digit ++ ) { count += count2sinRangeAtDigit ( number , digit ) ; } return count ; } document . write ( numberOf2sinRange ( 22 ) ) ; document . write ( " " + numberOf2sinRange ( 100 ) ) ;

Accumulator variables: count, digit
Iterator variables: digit
Javascript program:
function factorial ( n ) { let M = 1000000007 ; let f = 1 ; for ( let i = 1 ; i <= n ; i ++ ) return f ; }

Accumulator variables: i
Iterator variables: i
Javascript program:
function isTidy ( num ) { let prev = 10 ; while ( num != 0 ) { let rem = num % 10 ; num /= 10 ; if ( rem > prev ) return false ; prev = rem ; } return true ; } let num = 1556 ; document . write ( isTidy ( num ) ? " " : " " ) ;

Accumulator variables: num
Javascript program:
function squareFree ( n ) { let cnt = 0 ; for ( let i = 1 ; ; i ++ ) { let isSqFree = true ; for ( let j = 2 ; j * j <= i ; j ++ ) { if ( i % ( j * j ) == 0 ) { isSqFree = false ; break ; } } if ( isSqFree == true ) { cnt ++ ; if ( cnt == n ) return i ; } } } let n = 10 ; document . write ( " " + squareFree ( n ) ) ;

Accumulator variables: cnt, i, j
Iterator variables: i, j
Boolean variables: isSqFree
Javascript program:
let MAX_PRIME = 100000 ; let MAX_RES = 2000000000 ; function SieveOfEratosthenes ( a ) { let prime = new Array ( MAX_PRIME + 1 ) ; for ( let i = 0 ; i < ( MAX_PRIME + 1 ) ; i ++ ) { prime [ i ] = true ; } for ( let p = 2 ; p * p <= MAX_PRIME ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX_PRIME ; i += p ) prime [ i ] = false ; } } for ( let p = 2 ; p <= MAX_PRIME ; p ++ ) if ( prime [ p ] ) a . push ( p ) ; } function countSquares ( i , cur , k , a ) { let square = a [ i ] * a [ i ] ; let newCur = square * cur ; if ( newCur > k ) return 0 ; let cnt = Math . floor ( k / ( newCur ) ) ; cnt += countSquares ( i + 1 , cur , k , a ) ; cnt -= countSquares ( i + 1 , newCur , k , a ) ; return cnt ; } function squareFree ( n ) { let a = [ ] ; SieveOfEratosthenes ( a ) ; let low = 1 ; let high = MAX_RES ; while ( low < high ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; let c = mid - countSquares ( 0 , 1 , mid , a ) ; if ( c < n ) low = mid + 1 ; else high = mid ; } return low ; } let n = 10 ; document . write ( squareFree ( n ) ) ;

Index/key variables: i, p
Accumulator variables: cnt, i, p
Iterator variables: i, p
Javascript program:
function kFactors ( n , k ) { var P = Array ( ) ; while ( n % 2 == 0 ) { P . push ( 2 ) ; n = parseInt ( n / 2 ) ; } for ( i = 3 ; i * i <= n ; i = i + 2 ) { while ( n % i == 0 ) { n = parseInt ( n / i ) ; P . push ( i ) ; } } if ( n > 2 ) P . push ( n ) ; if ( P . length < k ) { document . write ( " " ) ; return ; } for ( i = 0 ; i < k - 1 ; i ++ ) document . write ( P [ i ] + " " ) ; var product = 1 ; for ( i = k - 1 ; i < P . length ; i ++ ) product = product * P [ i ] ; document . write ( product ) ; } var n = 54 , k = 3 ; kFactors ( n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nondecdigits ( n ) { let x = 0 ; for ( x = n ; x >= 1 ; x -- ) { let no = x ; let prev_dig = 11 ; let flag = true ; while ( no != 0 ) { if ( prev_dig < no % 10 ) { flag = false ; break ; } prev_dig = no % 10 ; no = Math . floor ( no / 10 ) ; } if ( flag == true ) break ; } return x ; } let n = 200 ; document . write ( nondecdigits ( n ) ) ;

Accumulator variables: x
Iterator variables: x
Boolean variables: flag
Javascript program:
function nondecdigits ( s ) { var m = s . length ; var a = Array . from ( { length : m + 1 } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < m ; i ++ ) a [ i ] = s . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; var level = m - 1 ; for ( i = m - 1 ; i > 0 ; i -- ) { if ( a [ i ] < a [ i - 1 ] ) { a [ i - 1 ] -- ; level = i - 1 ; } } if ( a [ 0 ] != 0 ) { for ( i = 0 ; i <= level ; i ++ ) document . write ( a [ i ] ) ; for ( i = level + 1 ; i < m ; i ++ ) document . write ( " " ) ; } else { for ( i = 1 ; i < level ; i ++ ) document . write ( a [ i ] ) ; for ( i = level + 1 ; i < m ; i ++ ) document . write ( " " ) ; } } var n = " " ; nondecdigits ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countDivisors ( n ) { let cnt = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) cnt ++ ; cnt = cnt + 2 ; } } return cnt ; } document . write ( " " + " " + countDivisors ( 100 ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function hasEvenNumberOfFactors ( n ) { let root_n = Math . sqrt ( n ) ; if ( ( root_n * root_n ) == n ) return false ; return true ; } function printStatusOfDoors ( n ) { for ( let i = 1 ; i <= n ; i ++ ) { if ( hasEvenNumberOfFactors ( i ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } } let n = 5 ; printStatusOfDoors ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function validate ( n ) { for ( let i = 0 ; i < 10 ; i ++ ) { let temp = n ; let count = 0 ; while ( temp > 0 ) { if ( temp % 10 == i ) count ++ ; if ( count > i ) return false ; temp /= 10 ; } } return true ; } let n = 1552793 ; if ( validate ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: count, i, temp
Iterator variables: i
Javascript program:
function divisibleBy36 ( num ) { let l = num . length ; if ( l == 0 ) return " " ; if ( l == 1 && num [ 0 ] != ' ' ) return " " ; let two_digit_num = ( num [ l - 2 ] - ' ' ) * 10 + ( num [ l - 1 ] - ' ' ) ; if ( two_digit_num % 4 != 0 ) return " " ; let sum = 0 ; for ( let i = 0 ; i < l ; i ++ ) sum += ( num [ i ] - ' ' ) ; if ( sum % 9 != 0 ) return " " ; return " " ; } let num = " " ; document . write ( divisibleBy36 ( num ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countDigits ( n ) { let count = 0 ; while ( n > 0 ) { count ++ ; n = Math . floor ( n / 10 ) ; } return count ; } function checkPrime ( n ) { if ( n <= 1 ) return - 1 ; if ( n <= 3 ) return 0 ; if ( n % 2 == 0 n % 3 == 0 ) return - 1 ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return - 1 ; return 0 ; } function printPrimePoints ( n ) { let count = countDigits ( n ) ; if ( count == 1 count == 2 ) { document . write ( " " ) ; return ; } let found = false ; for ( let i = 1 ; i < ( count - 1 ) ; i ++ ) { let left = Math . floor ( n / ( Math . pow ( 10 , count - i ) ) ) ; let right = n % ( Math . pow ( 10 , count - i - 1 ) ) ; if ( checkPrime ( left ) == 0 && checkPrime ( right ) == 0 ) { document . write ( i + " " ) ; found = true ; } } if ( found == false ) document . write ( " " ) ; } let n = 2317 ; printPrimePoints ( n ) ;

Accumulator variables: count, i
Iterator variables: i
Boolean variables: found
Javascript program:
function power ( num , n ) { if ( n == 0 ) return 1 ; else if ( n % 2 == 0 ) return power ( num , parseInt ( n / 2 ) ) * power ( num , parseInt ( n / 2 ) ) ; else return num * power ( num , parseInt ( n / 2 ) ) * power ( num , parseInt ( n / 2 ) ) ; } function checkRecursive ( x , n , curr_num , curr_sum ) { var results = 0 ; var p = power ( curr_num , n ) ; while ( p + curr_sum < x ) { results += checkRecursive ( x , n , curr_num + 1 , p + curr_sum ) ; curr_num ++ ; p = power ( curr_num , n ) ; } if ( p + curr_sum == x ) results ++ ; return results ; } var x = 10 , n = 2 ; document . write ( checkRecursive ( x , n , 1 , 0 ) ) ;

Accumulator variables: curr_num, results
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function printGenerators ( n ) { document . write ( " " ) ; for ( var i = 2 ; i < n ; i ++ ) if ( gcd ( i , n ) == 1 ) document . write ( i + " " ) ; } var n = 10 ; printGenerators ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( str ) { let n = str . length ; let digitSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) digitSum += ( str [ i ] - ' ' ) ; return ( digitSum % 3 == 0 ) ; } let str = " " ; let x = check ( str ) ? " " : " " ; document . write ( x ) ;

Index/key variables: i
Accumulator variables: digitSum, i
Iterator variables: i
Javascript program:
let MAX = 100001 ; ; let perfectDiv = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { perfectDiv [ i ] = 0 ; } function precomputeCounts ( ) { for ( let i = 1 ; i * i < MAX ; ++ i ) { for ( let j = i * i ; j < MAX ; j += i * i ) ++ perfectDiv [ j ] ; } } function countPerfectDivisors ( n ) { return perfectDiv [ n ] ; } precomputeCounts ( ) ; let n = 16 ; document . write ( " " + n + " " + countPerfectDivisors ( n ) + " " ) ; n = 12 ; document . write ( " " + n + " " + countPerfectDivisors ( n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAXN = 100001 ; let spf = new Array ( MAXN ) ; function sieve ( ) { spf [ 1 ] = 1 ; for ( let i = 2 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( let i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( let i = 3 ; i * i < MAXN ; i ++ ) { if ( spf [ i ] == i ) { for ( let j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } function getFactorization ( x ) { let ret = [ ] ; while ( x != 1 ) { ret . push ( spf [ x ] ) ; x = Math . floor ( x / spf [ x ] ) ; } return ret ; } sieve ( ) ; let x = 12246 ; document . write ( " " + x + " " ) ; let p = getFactorization ( x ) ; for ( let i = 0 ; i < p . length ; i ++ ) document . write ( p [ i ] + " " ) ; document . write ( " " ) ;

Index/key variables: i, j, x
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 100001 ; let INF = Number . MAX_VALUE ; let primedivisor = new Array ( MAX ) ; let dist = new Array ( MAX ) ; let pos = new Array ( MAX ) ; let divInd = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { primedivisor [ i ] = 0 ; dist [ i ] = 0 ; pos [ i ] = 0 ; divInd [ i ] = 0 ; } let divisors = [ ] ; function sieveOfEratosthenes ( ) { for ( let i = 2 ; i * i < MAX ; ++ i ) { if ( primedivisor [ i ] == 0 ) { for ( let j = i * i ; j < MAX ; j += i ) { primedivisor [ j ] = i ; } } } for ( let i = 1 ; i < MAX ; ++ i ) { if ( primedivisor [ i ] == 0 ) { primedivisor [ i ] = i ; } } } function findDivisors ( arr , n ) { for ( let i = 0 ; i < MAX ; ++ i ) { pos [ i ] = divInd [ i ] = - 1 ; dist [ i ] = INF ; } for ( let i = 0 ; i < n ; ++ i ) { let num = arr [ i ] ; while ( num > 1 ) { let div = primedivisor [ num ] ; divisors [ i ] . push ( div ) ; while ( num % div == 0 ) { num = Math . floor ( num / div ) ; } } } } function nearestGCD ( arr , n ) { findDivisors ( arr , n ) ; for ( let i = 0 ; i < n ; ++ i ) { for ( let div = 0 ; div < divisors [ i ] . length ; div ++ ) { if ( divInd [ divisors [ i ] [ div ] ] == - 1 ) { divInd [ divisors [ i ] [ div ] ] = i ; } else { let ind = divInd [ divisors [ i ] [ div ] ] ; divInd [ divisors [ i ] [ div ] ] = i ; if ( dist [ i ] > Math . abs ( ind - i ) ) { dist [ i ] = Math . abs ( ind - i ) ; pos [ i ] = ind + 1 ; } if ( dist [ ind ] > Math . abs ( ind - i ) ) { dist [ ind ] = Math . abs ( ind - i ) ; pos [ ind ] = i + 1 ; } } } } } for ( let i = 0 ; i < MAX ; i ++ ) { divisors . push ( [ ] ) ; } sieveOfEratosthenes ( ) ; let arr = [ 2 , 9 , 4 , 3 , 13 ] ; let n = arr . length ; nearestGCD ( arr , n ) ; for ( let i = 0 ; i < n ; ++ i ) { document . write ( pos [ i ] + " " ) ; }

Index/key variables: div, i, ind, j, num
Accumulator variables: div, i, j
Iterator variables: div, i, j
Javascript program:
function largestGCDSubsequence ( arr , n ) { var ans = 0 ; var maxele = Math . max ( ... arr ) ; for ( var i = 2 ; i <= maxele ; ++ i ) { var count = 0 ; for ( j = 0 ; j < n ; ++ j ) { if ( arr [ j ] % i == 0 ) ++ count ; } ans = Math . max ( ans , count ) ; } return ans ; } var arr = [ 3 , 6 , 2 , 5 , 4 ] ; var size = arr . length ; document . write ( largestGCDSubsequence ( arr , size ) ) ;

Index/key variables: j
Iterator variables: i, j
Javascript program:
class data { constructor ( val , steps ) { this . val = val ; this . steps = steps ; } } function minStepToReachOne ( N ) { let q = [ ] ; q . push ( new data ( N , 0 ) ) ; let st = new Set ( ) ; while ( q . length != 0 ) { let t = q . shift ( ) ; if ( t . val == 1 ) return t . steps ; if ( ! st . has ( t . val - 1 ) ) { q . push ( new data ( t . val - 1 , t . steps + 1 ) ) ; st . add ( t . val - 1 ) ; } for ( let i = 2 ; i * i <= t . val ; i ++ ) { if ( t . val % i == 0 && ! st . has ( t . val / i ) ) { q . push ( new data ( t . val / i , t . steps + 1 ) ) ; st . add ( t . val / i ) ; } } } return - 1 ; } let N = 17 ; document . write ( minStepToReachOne ( N ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: data
Javascript program:
var MAX = 1000006 ; function sieve ( count ) { for ( i = 2 ; i * i <= MAX ; i ++ ) { if ( count [ i ] == 0 ) { for ( j = 2 * i ; j < MAX ; j += i ) count [ j ] ++ ; count [ i ] = 1 ; } } } function query ( count , l , r ) { var sum = 0 ; for ( i = l ; i <= r ; i ++ ) sum += count [ i ] ; return sum ; } var count = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; sieve ( count ) ; document . write ( query ( count , 6 , 10 ) + " " + query ( count , 1 , 5 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function generateNumbers ( factor , n , k ) { let next = new Array ( k ) ; next . fill ( 0 ) ; for ( let i = 0 ; i < n ; ) { let toincrement = 0 ; for ( let j = 0 ; j < k ; j ++ ) if ( next [ j ] < next [ toincrement ] ) toincrement = j ; if ( output != next [ toincrement ] ) { output = next [ toincrement ] ; document . write ( next [ toincrement ] + " " ) ; i ++ ; } next [ toincrement ] += factor [ toincrement ] ; } } let factor = [ 3 , 5 , 7 ] ; let n = 10 ; let k = factor . length ; generateNumbers ( factor , n , k ) ;

Index/key variables: j, toincrement
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } function multiplicativeOrder ( A , N ) { if ( GCD ( A , N ) != 1 ) return - 1 ; let result = 1 ; let K = 1 ; while ( K < N ) { result = ( result * A ) % N ; if ( result == 1 ) return K ; K ++ ; } return - 1 ; } let A = 4 , N = 7 ; document . write ( multiplicativeOrder ( A , N ) ) ;

Accumulator variables: K
Javascript program:
function sumOfRange ( a , b ) { let i = ( a * ( a + 1 ) ) >> 1 ; let j = ( b * ( b + 1 ) ) >> 1 ; return ( i - j ) ; } function sumofproduct ( n ) { let sum = 0 ; let root = Math . floor ( Math . sqrt ( n ) ) ; for ( let i = 1 ; i <= root ; i ++ ) { let up = Math . floor ( n / i ) ; let low = Math . max ( Math . floor ( n / ( i + 1 ) ) , root ) ; sum += ( i * sumOfRange ( up , low ) ) ; sum += ( i * Math . floor ( n / i ) ) ; } return sum ; } let n = 10 ; document . write ( sumofproduct ( n ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function power ( x , y , p ) { while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function findPrimefactors ( s , n ) { while ( n % 2 == 0 ) { s . add ( 2 ) ; n = n / 2 ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { s . add ( i ) ; n = n / i ; } } if ( n > 2 ) s . add ( n ) ; } function findPrimitive ( n ) { let s = new Set ( ) ; if ( isPrime ( n ) == false ) return - 1 ; let phi = n - 1 ; findPrimefactors ( s , phi ) ; for ( let r = 2 ; r <= phi ; r ++ ) { let flag = false ; for ( let it of s ) { if ( power ( r , phi / it , n ) == 1 ) { flag = true ; break ; } } if ( flag == false ) return r ; } return - 1 ; } let n = 761 ; document . write ( " " + n + " " + findPrimitive ( n ) ) ;

Accumulator variables: r
Iterator variables: i, it, r
Boolean variables: flag
Javascript program:
function minPower ( n , x ) { if ( x == 1 ) return n ; let ans = 0 ; while ( n > 0 ) { ans += ( n % x ) ; n = Math . floor ( n / x ) ; } return ans ; } let n = 5 , x = 3 ; document . write ( minPower ( n , x ) + " " ) ;

Accumulator variables: ans
Javascript program:
function calSum ( n ) { let a = 3 , b = 0 , c = 2 ; return 3 ; return 3 ; return 5 ; let sum = 5 ; while ( n > 2 ) { let d = a + b ; sum += d ; a = b ; b = c ; c = d ; n -- ; } return sum ; } let n = 9 ; document . write ( calSum ( n ) ) ;

Accumulator variables: n, sum
Javascript program:
function findKHCF ( x , y , k ) { let small = Math . min ( x , y ) ; let count = 1 ; for ( let i = 2 ; i <= small ; i ++ ) { if ( x % i == 0 && y % i == 0 ) count ++ ; if ( count == k ) return i ; } return - 1 ; } let x = 4 , y = 24 , k = 3 ; document . write ( findKHCF ( x , y , k ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findMinNumber ( n ) { let count = 0 ; let ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 2 ) ans *= 2 ; for ( let i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 2 ) ans *= i ; } if ( n > 2 ) ans *= n ; return ans ; } let n = 72 ; document . write ( findMinNumber ( n ) + " " ) ;

Accumulator variables: ans, count, i, n
Iterator variables: i