dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function powerfulIntegers ( x , y , bound ) { var s = new Set ( ) ; var powersOfY = [ ] ; var i ; powersOfY . push ( 1 ) ; for ( i = y ; i < bound && y != 1 ; i = i * y ) powersOfY . push ( i ) ; i = 0 ; while ( true ) { var xPowI = Math . pow ( x , i ) ; powersOfY . forEach ( j => { var num = xPowI + j ; if ( num <= bound ) s . add ( num ) ; } ) ; if ( xPowI >= bound x == 1 ) break ; i ++ ; } [ ... s ] . sort ( ( a , b ) => a - b ) . forEach ( itr => { document . write ( itr + " " ) } ) ; } var x = 2 , y = 3 , bound = 10 ; powerfulIntegers ( x , y , bound ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function candies ( n , k ) { var count = 0 ; var ind = 1 ; var arr = Array ( k ) ; for ( i = 0 ; i < k ; i ++ ) arr [ i ] = 0 ; while ( n > 0 ) { var f1 = ( ind - 1 ) * k ; var f2 = ind * k ; var sum1 = ( f1 * ( f1 + 1 ) ) / 2 ; var sum2 = ( f2 * ( f2 + 1 ) ) / 2 ; var res = sum2 - sum1 ; if ( res <= n ) { count ++ ; n -= res ; ind ++ ; { var i = 0 ; var term = ( ( ind - 1 ) * k ) + 1 ; while ( n > 0 ) { if ( term <= n ) { arr [ i ++ ] = term ; n -= term ; term ++ ; } else { arr [ i ++ ] = n ; n = 0 ; } } } } for ( i = 0 ; i < k ; i ++ ) arr [ i ] += ( count * ( i + 1 ) ) + ( k * ( count * ( count - 1 ) ) / 2 ) ; for ( i = 0 ; i < k ; i ++ ) document . write ( arr [ i ] + " " ) ; } var n = 10 , k = 3 ; candies ( n , k ) ;

Index/key variables: i
Accumulator variables: count, i, ind, n, term
Iterator variables: i
Javascript program:
function candies ( n , k ) { var count = 0 ; var ind = 1 ; var arr = Array ( k ) . fill ( 0 ) ; for ( i = 0 ; i < k ; i ++ ) arr [ i ] = 0 ; var low = 0 , high = n ; while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; var sum = parseInt ( ( mid * ( mid + 1 ) ) / 2 ) ; if ( sum <= n ) { count = parseInt ( mid / k ) ; low = mid + 1 ; } else { high = mid - 1 ; } } var last = ( count * k ) ; n -= ( last * ( last + 1 ) ) / 2 ; var j = 0 ; var term = ( count * k ) + 1 ; while ( n > 0 ) { if ( term <= n ) { arr [ j ++ ] = term ; n -= term ; term ++ ; } else { arr [ j ] += n ; n = 0 ; } } for ( i = 0 ; i < k ; i ++ ) arr [ i ] += ( count * ( i + 1 ) ) + ( k * ( count * ( count - 1 ) ) / 2 ) ; for ( i = 0 ; i < k ; i ++ ) document . write ( arr [ i ] + " " ) ; } var n = 7 , k = 4 ; candies ( n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j, n, term
Iterator variables: i
Javascript program:
function printSmallest ( a ) { a . sort ( function ( a , b ) { return a - b } ) ; let i , j , num ; for ( i = 0 ; i < 3 ; i ++ ) { if ( a [ i ] % 3 == 0 ) { return a [ i ] ; } } for ( i = 0 ; i < 3 ; i ++ ) { for ( j = 0 ; j < 3 ; j ++ ) { num = ( a [ i ] * 10 ) + a [ j ] ; if ( num % 3 == 0 ) { return num ; } } } return a [ 0 ] * 100 + a [ 0 ] * 10 + a [ 0 ] ; } let arr = [ 7 , 7 , 1 ] ; document . write ( printSmallest ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function updateMatrix ( n , q , mat ) { let i , j ; for ( i = 0 ; i < q . length ; i ++ ) { let X1 = q [ i ] [ 0 ] ; let Y1 = q [ i ] [ 1 ] ; let X2 = q [ i ] [ 2 ] ; let Y2 = q [ i ] [ 3 ] ; mat [ X1 ] [ Y1 ] ++ ; if ( Y2 + 1 < n ) mat [ X2 ] [ Y2 + 1 ] -- ; else if ( X2 + 1 < n ) mat [ X2 + 1 ] [ 0 ] -- ; } let sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { sum += mat [ i ] [ j ] ; document . write ( sum + " " ) ; } document . write ( " " ) ; } } let n = 5 ; let mat = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { mat [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { mat [ i ] [ j ] = 0 ; } } let q = [ [ 0 , 0 , 1 , 2 ] , [ 1 , 2 , 3 , 4 ] , [ 1 , 4 , 3 , 4 ] ] ; updateMatrix ( n , q , mat ) ;

Index/key variables: X1, X2, Y1, i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( arr [ n - 1 ] . toFixed ( 6 ) ) ; } function replaceMax ( arr , n ) { let max = arr [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } let min = arr [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < min ) min = arr [ i ] ; } let range = max - min ; let coeffOfRange = range / ( max + min ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == max ) { arr [ i ] = coeffOfRange ; break ; } } printArr ( arr , n ) ; } let arr = [ 15 , 16 , 10 , 9 , 6 , 7 , 17 ] ; let n = arr . length ; replaceMax ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function divide ( a , b ) { for ( let i = 2 ; i <= Math . min ( a , b ) ; i ++ ) { while ( a % i == 0 && b % i == 0 ) { a = a / i ; b = b / i ; } } document . write ( " " + a + " " + b + " " ) ; } let A = 10 , B = 15 ; divide ( A , B ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function FindAllElements ( n , k ) { let sum = k ; let A = new Array ( k ) . fill ( 1 ) ; for ( let i = k - 1 ; i >= 0 ; -- i ) { while ( sum + A [ i ] <= n ) { sum += A [ i ] ; A [ i ] *= 2 ; } } if ( sum != n ) { document . write ( " " ) ; } else { for ( let i = 0 ; i < k ; ++ i ) document . write ( A [ i ] + " " ) ; } } let n = 12 ; let k = 6 ; FindAllElements ( n , k ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Javascript program:
function removeZero ( n ) { let res = 0 ; let d = 1 ; while ( n > 0 ) { if ( n % 10 != 0 ) { res += ( n % 10 ) * d ; d *= 10 ; } n = Math . floor ( n / 10 ) ; } return res ; } function isEqual ( a , b ) { if ( removeZero ( a ) + removeZero ( b ) == removeZero ( a + b ) ) return true ; return false ; } let a = 105 , b = 106 ; if ( isEqual ( a , b ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: d, res
Javascript program:
function sumArray ( arr , n ) { let leftSum = new Array ( n ) ; let rightSum = new Array ( n ) ; let Sum = new Array ( n ) ; let i = 0 , j = 0 ; leftSum [ 0 ] = 0 ; rightSum [ n - 1 ] = 0 ; for ( i = 1 ; i < n ; i ++ ) leftSum [ i ] = arr [ i - 1 ] + leftSum [ i - 1 ] ; for ( j = n - 2 ; j >= 0 ; j -- ) rightSum [ j ] = arr [ j + 1 ] + rightSum [ j + 1 ] ; for ( i = 0 ; i < n ; i ++ ) Sum [ i ] = leftSum [ i ] + rightSum [ i ] ; for ( i = 0 ; i < n ; i ++ ) document . write ( Sum [ i ] + " " ) ; } let arr = [ 3 , 6 , 4 , 8 , 9 ] ; let n = arr . length ; sumArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minimumX ( n , k ) { let mini = Number . MAX_VALUE ; for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { let fir = i ; let sec = parseInt ( n / i , 10 ) ; let num1 = fir * k + sec ; let res = parseInt ( ( num1 / k ) , 10 ) * ( num1 % k ) ; if ( res == n ) mini = Math . min ( num1 , mini ) ; let num2 = sec * k + fir ; res = parseInt ( ( num2 / k ) , 10 ) * ( num2 % k ) ; if ( res == n ) mini = Math . min ( num2 , mini ) ; } } return mini ; } let n = 4 , k = 6 ; document . write ( minimumX ( n , k ) + " " ) ; n = 5 , k = 5 ; document . write ( minimumX ( n , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumX ( n , k ) { let ans = Number . MAX_VALUE ; for ( let rem = k - 1 ; rem > 0 ; rem -- ) { if ( n % rem == 0 ) ans = Math . min ( ans , rem + ( n / rem ) * k ) ; } return ans ; } let n = 4 , k = 6 ; document . write ( minimumX ( n , k ) + " " ) ; n = 5 , k = 5 ; document . write ( minimumX ( n , k ) ) ;

Accumulator variables: rem
Iterator variables: rem
Javascript program:
function isPerfect ( N ) { if ( ( Math . sqrt ( N ) - Math . floor ( Math . sqrt ( N ) ) ) != 0 ) return false ; return true ; } function getClosestPerfectSquare ( N ) { if ( isPerfect ( N ) ) { document . write ( N + " " + " " + " " ) ; return ; } let aboveN = - 1 , belowN = - 1 ; let n1 ; n1 = N + 1 ; while ( true ) { if ( isPerfect ( n1 ) ) { aboveN = n1 ; break ; } else n1 ++ ; } n1 = N - 1 ; while ( true ) { if ( isPerfect ( n1 ) ) { belowN = n1 ; break ; } else n1 -- ; } let diff1 = aboveN - N ; let diff2 = N - belowN ; if ( diff1 > diff2 ) document . write ( belowN + " " + diff2 ) ; else document . write ( aboveN + " " + diff1 ) ; } let N = 1500 ; getClosestPerfectSquare ( N ) ;

Accumulator variables: n1
Javascript program:
function findLargestDivisor ( n ) { for ( let i = 2 ; i < Math . sqrt ( n ) + 1 ; i ++ ) { while ( n % ( i * i ) == 0 ) { n = n / i ; } } return n ; } let n = 12 ; document . write ( findLargestDivisor ( n ) + " " ) ; n = 97 ; document . write ( findLargestDivisor ( n ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function compare ( a , b ) { if ( a < b ) { return - 1 ; } else if ( a > b ) { return 1 ; } else { return 0 ; } } function checkIsAP ( arr , n ) { if ( n == 1 ) return true ; arr . sort ( compare ) ; let d = arr [ 1 ] - arr [ 0 ] ; for ( let i = 2 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ; return true ; } let arr = [ 20 , 15 , 5 , 0 , 10 ] ; let n = arr . length ; ( checkIsAP ( arr , n ) ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isTriPerfect ( n ) { let sum = 1 + n ; let i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) { if ( parseInt ( n / i , 10 ) == i ) sum = sum + i ; else sum = sum + i + parseInt ( n / i , 10 ) ; } i += 1 ; } if ( sum == 3 * n & n != 1 ) return true ; else return false ; } let n = 120 ; if ( isTriPerfect ( n ) ) document . write ( n + " " ) ;

Accumulator variables: i
Javascript program:
function findTwoThreePrime ( l , r ) { if ( l == 1 ) l ++ ; let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { let num = i ; while ( num % 2 == 0 ) num = parseInt ( num / 2 , 10 ) ; while ( num % 3 == 0 ) num = parseInt ( num / 3 , 10 ) ; if ( num == 1 ) count ++ ; } return count ; } let l = 1 , r = 10 ; document . write ( findTwoThreePrime ( l , r ) ) ;

Accumulator variables: count, i, l
Iterator variables: i
Javascript program:
function getNumber ( s ) { let number_of_digits = s . length ; let freq = new Array ( 10 ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < number_of_digits ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { freq [ s [ i ] . charCodeAt ( ) - 48 ] += 1 ; } if ( s [ i ] == ' ' ) { freq [ 2 ] += 2 ; freq [ 3 ] ++ ; } if ( s [ i ] == ' ' ) { freq [ 5 ] ++ ; freq [ 3 ] ++ ; } if ( s [ i ] == ' ' ) { freq [ 7 ] ++ ; freq [ 2 ] += 3 ; } if ( s [ i ] == ' ' ) { freq [ 7 ] ++ ; freq [ 3 ] += 2 ; freq [ 2 ] ++ ; } } let t = " " ; if ( freq [ 1 ] == number_of_digits || freq [ 0 ] == number_of_digits || ( freq [ 0 ] + freq [ 1 ] ) == number_of_digits ) { return s ; } else { for ( let i = 9 ; i >= 2 ; i -- ) { let ctr = freq [ i ] ; while ( ( ctr -- ) > 0 ) { t += String . fromCharCode ( i + 48 ) ; } } return t ; } } let s = " " ; document . write ( getNumber ( s ) ) ;

Index/key variables: i
Accumulator variables: ctr, i, t
Iterator variables: i
Javascript program:
function reversDigits ( num ) { let rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = parseInt ( num / 10 , 10 ) ; } return rev_num ; } function icanobifNumbers ( N ) { let first = 0 , second = 1 ; if ( N == 1 ) document . write ( first ) ; else if ( N == 2 ) document . write ( first + " " + second ) ; else { document . write ( first + " " + second + " " ) ; for ( let i = 3 ; i <= N ; i ++ ) { let x = reversDigits ( first ) ; let y = reversDigits ( second ) ; document . write ( x + y + " " ) ; let temp = second ; second = x + y ; first = temp ; } } } let N = 12 ; icanobifNumbers ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function addNDigits ( a , b , n ) { let num = a ; for ( let i = 0 ; i <= 9 ; i ++ ) { let tmp = a * 10 + i ; if ( tmp % b == 0 ) { a = tmp ; break ; } } if ( num == a ) return - 1 ; for ( let j = 0 ; j < n - 1 ; j ++ ) a *= 10 ; return a ; } let a = 5 , b = 3 , n = 3 ; document . write ( addNDigits ( a , b , n ) ) ;

Accumulator variables: a, i, j
Iterator variables: i, j
Javascript program:
function Triplets ( n ) { var ans = 0 ; for ( let i = 1 ; i <= n ; ++ i ) { for ( let j = i ; j <= n ; ++ j ) { var x = i * i + j * j ; var y = parseInt ( Math . sqrt ( x ) ) ; if ( y * y == x && y <= n ) ++ ans ; } } return ans ; } var n = 10 ; document . write ( Triplets ( n ) ) ;

Iterator variables: i, j
Javascript program:
function solve ( n , base ) { var sum = 0 ; while ( n > 0 ) { var remainder = n % base ; sum += remainder ; n = parseInt ( n / base ) ; } return sum ; } function SumsOfDigits ( n ) { var sum = 0 ; for ( base = 2 ; base <= n / 2 ; ++ base ) sum += solve ( n , base ) ; document . write ( sum ) ; } var n = 8 ; SumsOfDigits ( n ) ;

Accumulator variables: sum
Iterator variables: base
Javascript program:
function checkPerfectcube ( n ) { let d = Math . cbrt ( n ) ; if ( d * d * d == n ) return true ; return false ; } function largestNonPerfectcubeNumber ( a , n ) { let maxi = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! checkPerfectcube ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } let a = [ 16 , 64 , 25 , 2 , 3 , 10 ] ; let n = a . length ; document . write ( largestNonPerfectcubeNumber ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkIfPossibleRec ( x , a , b , isPossible , n ) { if ( x > n ) return ; if ( isPossible [ x ] ) return ; isPossible [ x ] = true ; checkIfPossibleRec ( x + a , a , b , isPossible , n ) ; checkIfPossibleRec ( x + b , a , b , isPossible , n ) ; } function checkPossible ( n , a , b ) { var isPossible = Array ( n + 1 ) . fill ( false ) ; checkIfPossibleRec ( 0 , a , b , isPossible , n ) ; return isPossible [ n ] ; } var a = 3 , b = 7 , n = 8 ; if ( checkPossible ( a , b , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: n, x
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function sumcommDiv ( a , b ) { var n = gcd ( a , b ) ; var sum = 0 ; for ( var i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum += i ; else sum += ( n / i ) + i ; } } return sum ; } var a = 10 , b = 15 ; document . write ( " " + sumcommDiv ( a , b ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minOperations ( A , n ) { if ( ( n & 1 ) > 0 ) return - 1 ; let zeros = 0 , consZeros = 0 , ones = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( A [ i ] == 0 ) zeros ++ ; else ones ++ ; if ( i + 1 < n ) { if ( A [ i ] == 0 && A [ i + 1 ] == 0 ) consZeros ++ ; } } if ( A [ 0 ] == A [ n - 1 ] && A [ 0 ] == 0 ) consZeros ++ ; if ( zeros == ones ) return consZeros ; else return - 1 ; } let A = [ 1 , 1 , 0 , 0 ] ; let n = A . length ; document . write ( minOperations ( A , n ) ) ;

Index/key variables: i
Accumulator variables: consZeros, ones, zeros
Iterator variables: i
Javascript program:
function countdig ( m ) { if ( m == 0 ) return 0 ; else return 1 + countdig ( parseInt ( m / 10 ) ) ; } function countSteps ( x ) { var c = 0 ; var last = x ; while ( last > 0 ) { var digits = countdig ( last ) ; digits -= 1 ; var divisor = parseInt ( Math . pow ( 10 , digits ) ) ; var first = parseInt ( last / divisor ) ; var lastnumber = first * divisor ; var skipped = parseInt ( ( last - lastnumber ) / first ) ; skipped += 1 ; c += skipped ; last = last - ( first * skipped ) ; } return c ; } var n = 14 ; document . write ( countSteps ( n ) ) ;

Accumulator variables: c, digits, skipped
Javascript program:
function allOddDigits ( n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 == 0 ) return false ; n = parseInt ( n / 10 ) ; } return true ; } function largestNumber ( n ) { if ( parseInt ( n % 2 ) == 0 ) n -- ; for ( i = n ; i > 0 ; i -= 2 ) if ( allOddDigits ( i ) ) return i ; } var N = 23 ; document . write ( largestNumber ( N ) ) ;

Accumulator variables: i, n
Iterator variables: i
Javascript program:
function largestNumber ( n ) { var s = " " ; var duplicate = n ; while ( n > 0 ) { s = String . fromCharCode ( n % 10 + 48 ) + s ; n = parseInt ( n / 10 ) ; } var index = - 1 ; for ( i = 0 ; i < s . length ; i ++ ) { if ( ( ( s . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) % 2 & 1 ) == 0 ) { index = i ; break ; } } if ( index == - 1 ) return duplicate ; var num = 0 ; for ( i = 0 ; i < index ; i ++ ) num = num * 10 + ( s . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; num = num * 10 + ( s . charAt ( index ) . charCodeAt ( 0 ) - ( ' ' ) . charCodeAt ( 0 ) - 1 ) ; for ( i = index + 1 ; i < s . length ; i ++ ) num = num * 10 + 9 ; return num ; } var N = 24578 ; document . write ( largestNumber ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countOrderedPairs ( N ) { var count_pairs = 0 ; for ( var i = 1 ; i <= Math . sqrt ( N - 1 ) ; ++ i ) { for ( var j = i ; j * i < N ; ++ j ) ++ count_pairs ; } count_pairs *= 2 ; count_pairs -= parseInt ( Math . sqrt ( N - 1 ) ) ; return count_pairs ; } var N = 5 ; document . write ( countOrderedPairs ( N ) ) ;

Accumulator variables: count_pairs
Iterator variables: i, j
Javascript program:
function pairwiseDifference ( arr , n ) { var diff ; for ( i = 0 ; i < n - 1 ; i ++ ) { diff = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; document . write ( diff + " " ) ; } } var arr = [ 4 , 10 , 15 , 5 , 6 ] ; var n = arr . length ; pairwiseDifference ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumAP ( n , d ) { n = parseInt ( n / d ) ; return ( n ) * ( ( 1 + n ) * parseInt ( d ) / 2 ) ; } function sumMultiples ( n ) { n -- ; return sumAP ( n , 2 ) + sumAP ( n , 5 ) - sumAP ( n , 10 ) ; } n = 20 ; document . write ( sumMultiples ( n ) ) ;

Accumulator variables: n
Javascript program:
function markingScheme ( N , answerKey , studentAnswer ) { var positive = 0 , negative = 0 , notattempt = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( studentAnswer [ i ] == 0 ) notattempt ++ ; else if ( answerKey [ i ] == studentAnswer [ i ] ) positive ++ ; else if ( answerKey [ i ] != studentAnswer [ i ] ) negative ++ ; } return ( positive * 3 ) + ( negative * - 1 ) ; } var answerKey = [ 1 , 2 , 3 , 4 , 1 ] ; var studentAnswer = [ 1 , 2 , 3 , 4 , 0 ] ; var N = answerKey . length ; document . write ( markingScheme ( N , answerKey , studentAnswer ) ) ;

Index/key variables: i
Accumulator variables: i, negative, notattempt, positive
Iterator variables: i
Javascript program:
let MAX = 10000 ; let prime = new Array ( MAX + 1 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { prime [ 1 ] = false ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function solve ( n ) { let count = 0 ; let num = 1 ; let prod = 1 ; while ( count < n ) { if ( prime [ num ] == true ) { prod *= num ; count ++ ; } num ++ ; } return prod ; } SieveOfEratosthenes ( ) ; let n = 5 ; document . write ( solve ( n ) ) ;

Index/key variables: i, num, p
Accumulator variables: count, i, num, p, prod
Iterator variables: i, p
Javascript program:
function divisor ( a ) { let div = 1 , count = 0 ; for ( let i = 2 ; i <= Math . sqrt ( a ) ; i ++ ) { while ( a % i == 0 ) { count ++ ; a = parseInt ( a / i , 10 ) ; } div = div * ( count + 1 ) ; count = 0 ; } if ( a > 1 ) { div = div * ( 2 ) ; } return div ; } function OddDivCount ( a , b ) { let res = 0 ; for ( let i = a ; i <= b ; ++ i ) { let divCount = divisor ( i ) ; if ( divCount % 2 == 1 ) { ++ res ; } } return res ; } let a = 1 , b = 10 ; document . write ( OddDivCount ( a , b ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function Check_is_possible ( l , r , k ) { var div_count = ( r / k ) - ( l / k ) ; if ( l % k == 0 ) { div_count ++ ; } return ( div_count > 1 ) ; } var l = 30 , r = 70 , k = 10 ; if ( Check_is_possible ( l , r , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: div_count
Javascript program:
function isPerfectPower ( n ) { if ( n == 1 ) { return true ; } for ( var x = 2 ; x <= Math . sqrt ( n ) ; x ++ ) { var y = 2 ; var p = parseInt ( Math . pow ( x , y ) ) ; while ( p <= n && p > 0 ) { if ( p == n ) { return true ; } y ++ ; p = parseInt ( Math . pow ( x , y ) ) ; } } return false ; } function isStrongNumber ( n ) { var count = new Map ( ) ; while ( n % 2 == 0 ) { n = n / 2 ; if ( count . has ( 2 ) ) { count . set ( 2 , count . get ( 2 ) + 1 ) ; } else { count . set ( 2 , 1 ) ; } } for ( var i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { n = n / i ; if ( count . has ( i ) ) { count . set ( i , count . get ( i ) + 1 ) ; } else { count . set ( i , 1 ) ; } } } if ( n > 2 ) { if ( count . has ( n ) ) { count . set ( n , count . get ( n ) + 1 ) ; } else { count . set ( n , 1 ) ; } } var flag = 0 ; const iterator = count [ Symbol . iterator ] ( ) ; let itr = iterator . next ( ) for ( let i = 0 ; i < count . size ; i ++ ) { console . log ( itr . value , itr . done ) if ( itr . value == 1 ) { flag = 1 ; break ; } itr = iterator . next ( ) } if ( flag == 1 ) { return false ; } else { return true ; } } function isTrojan ( n ) { if ( ! isPerfectPower ( n ) && isStrongNumber ( n ) ) { return true ; } else { return false ; } } var n = 108 ; if ( isTrojan ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: i, x, y
Iterator variables: i, x
Javascript program:
function CalculateDifference ( arr , n ) { var max_val = Number . MIN_VALUE ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max_val ) max_val = arr [ i ] ; } var prime = Array ( max_val + 1 ) ; for ( i = 0 ; i <= max_val ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } var S1 = 0 , S2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { S1 += arr [ i ] ; } else if ( arr [ i ] != 1 ) { S2 += arr [ i ] ; } } return Math . abs ( S2 - S1 ) ; } var arr = [ 1 , 3 , 5 , 10 , 15 , 7 ] ; var n = arr . length ; document . write ( CalculateDifference ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: S1, S2, i, p
Iterator variables: i, p
Javascript program:
function sum ( x , n ) { let total = 1.0 ; let previous = 1.0 ; for ( let i = 1 ; i <= n ; i ++ ) { previous = ( ( previous * x ) / ( i + 1 ) ) ; total = total + previous ; } return total ; } let x = 5 , n = 4 ; document . write ( " " + sum ( x , n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function numberOfDivisors ( num ) { let c = 0 ; for ( let i = 1 ; i <= num ; i ++ ) { if ( num % i == 0 ) { c += 1 ; } } return c ; } function countNumbers ( n ) { let c = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( numberOfDivisors ( i ) == 9 ) c += 1 ; } return c ; } let n = 1000 ; document . write ( countNumbers ( n ) ) ;

Accumulator variables: c, i
Iterator variables: i
Javascript program:
function numberOfDistinct ( n ) { var ans = 0 ; for ( i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { ans ++ ; if ( ( n / i ) != i ) ans ++ ; } } return ans ; } var n = 3 ; document . write ( numberOfDistinct ( n ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var MAX = 10000 ; var arr = [ ] ; function ulam ( ) { arr . push ( 1 ) ; arr . push ( 2 ) ; for ( var i = 3 ; i < MAX ; i ++ ) { var count = 0 ; for ( var j = 0 ; j < arr . length - 1 ; j ++ ) { for ( var k = j + 1 ; k < arr . length ; k ++ ) { if ( arr [ j ] + arr [ k ] == i ) { count ++ ; } if ( count > 1 ) break ; } if ( count > 1 ) break ; } if ( count == 1 ) { arr . push ( i ) ; } } } ulam ( ) ; var n = 9 ; document . write ( arr [ n - 1 ] ) ;

Index/key variables: j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Javascript program:
function numberOfSolutions ( n ) { let c = 0 ; for ( let x = 0 ; x <= n ; ++ x ) if ( n == x + n ^ x ) ++ c ; return c ; } let n = 3 ; document . write ( numberOfSolutions ( n ) ) ;

Iterator variables: x