dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function countXorPair ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) if ( ( arr [ i ] ^ arr [ j ] ) % 2 == 1 ) count ++ ; } return count ; } let arr = [ 1 , 2 , 3 ] ; document . write ( countXorPair ( arr , arr . length ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function powmod ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function discreteLogarithm ( a , b , m ) { let n = ( parseInt ( Math . sqrt ( m ) , 10 ) + 1 ) ; let value = new Array ( m ) ; value . fill ( 0 ) ; for ( let i = n ; i >= 1 ; -- i ) value [ powmod ( a , i * n , m ) ] = i ; for ( let j = 0 ; j < n ; ++ j ) { let cur = ( powmod ( a , j , m ) * b ) % m ; if ( value [ cur ] > 0 ) { let ans = value [ cur ] * n - j ; if ( ans < m ) return ans ; } } return - 1 ; } let a = 2 , b = 3 , m = 5 ; document . write ( discreteLogarithm ( a , b , m ) + " " ) ; a = 3 ; b = 7 ; m = 11 ; document . write ( discreteLogarithm ( a , b , m ) + " " ) ;

Index/key variables: cur
Iterator variables: i, j
Javascript program:
function discreteLogarithm ( a , b , m ) { let n = parseInt ( Math . sqrt ( m ) , 10 ) + 1 ; let an = 1 ; for ( let i = 0 ; i < n ; ++ i ) an = ( an * a ) % m ; let value = new Array ( m ) ; value . fill ( 0 ) ; for ( let i = 1 , cur = an ; i <= n ; ++ i ) { if ( value [ cur ] == 0 ) value [ cur ] = i ; cur = ( cur * an ) % m ; } for ( let i = 0 , cur = b ; i <= n ; ++ i ) { if ( value [ cur ] > 0 ) { let ans = value [ cur ] * n - i ; if ( ans < m ) return ans ; } cur = ( cur * a ) % m ; } return - 1 ; } let a = 2 , b = 3 , m = 5 ; document . write ( discreteLogarithm ( a , b , m ) + " " ) ; a = 3 ; b = 7 ; m = 11 ; document . write ( discreteLogarithm ( a , b , m ) ) ;

Index/key variables: cur
Iterator variables: i
Javascript program:
function nthprimedigitsnumber ( number ) { let rem ; let num = " " ; while ( number > 0 ) { rem = number % 4 ; switch ( rem ) { case 1 : num += ' ' ; break ; case 2 : num += ' ' ; break ; case 3 : num += ' ' ; break ; case 0 : num += ' ' ; break ; } if ( number % 4 == 0 ) number -- ; number = parseInt ( number / 4 , 10 ) ; } let st = num . split ( ' ' ) ; st . reverse ( ) ; return ( st . join ( " " ) ) ; } let number = 21 ; document . write ( nthprimedigitsnumber ( 10 ) + " " ) ; document . write ( nthprimedigitsnumber ( number ) ) ;

Accumulator variables: num, number
Javascript program:
function countPairs ( N ) { let count = 0 ; for ( let i = 1 ; i <= parseInt ( Math . pow ( N , ( 1.0 / 3.0 ) ) , 10 ) ; i ++ ) { let cb = i * i * i ; let diff = N - cb ; let cbrtDiff = parseInt ( Math . pow ( diff , ( 1.0 / 3.0 ) ) , 10 ) ; if ( cbrtDiff * cbrtDiff * cbrtDiff == diff ) count ++ ; } return count ; } for ( let i = 1 ; i <= 10 ; i ++ ) document . write ( " " + i + " " + countPairs ( i ) + " " + " " ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function printEqualModNumbers ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; d = arr [ n - 1 ] - arr [ 0 ] ; if ( d == 0 ) { document . write ( " " ) ; return ; } v = new Array ( ) ; for ( i = 1 ; i * i <= d ; i ++ ) { if ( d % i == 0 ) { v . push ( i ) ; if ( i != d / i ) v . push ( d / i ) ; } } for ( i = 0 ; i < v . length ; i ++ ) { temp = arr [ 0 ] % v [ i ] ; j = 1 ; for ( ; j < n ; j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ; if ( j == n ) document . write ( v [ i ] + " " ) ; } } let arr = new Array ( 38 , 6 , 34 ) ; printEqualModNumbers ( arr , arr . length ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function FirstDigit ( arr , n ) { let S = 0 ; for ( let i = 0 ; i < n ; i ++ ) S = S + Math . log10 ( arr [ i ] * 1.0 ) ; let fract_S = S - Math . floor ( S ) ; let ans = parseInt ( Math . pow ( 10 , fract_S ) , 10 ) ; return ans ; } let arr = [ 5 , 8 , 3 , 7 ] ; let n = arr . length ; document . write ( FirstDigit ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countDigit ( n ) { var temp = n , count = 0 ; while ( temp != 0 ) { var d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 ) count ++ ; } return count ; } var n = 1012 ; document . write ( countDigit ( n ) ) ;

Accumulator variables: count, temp
Javascript program:
function makeOdd ( n ) { if ( n % 2 != 0 ) return 1 ; var ans = 1 ; while ( n % 2 == 0 ) { n = parseInt ( n / 2 ) ; ans *= 2 ; } return ans ; } var n = 36 ; var res = makeOdd ( n ) ; document . write ( res ) ;

Accumulator variables: ans
Javascript program:
function printCubes ( a , b ) { let acrt = parseInt ( Math . pow ( a , 1 / 3 ) , 10 ) ; let bcrt = parseInt ( Math . pow ( b , 1 / 3 ) , 10 ) ; for ( let i = acrt ; i <= bcrt ; i ++ ) if ( i * i * i >= a && i * i * i <= b ) document . write ( ( i * i * i ) + " " ) ; } let a = 24 ; let b = 576 ; document . write ( " " + " " + " " ) ; printCubes ( a , b ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function number0f2s ( n ) { let count = 0 ; while ( n > 0 ) { if ( n % 10 == 2 ) count ++ ; n = parseInt ( n / 10 , 10 ) ; } return count ; } function numberOf2sinRange ( n ) { let count = 0 ; for ( let i = 2 ; i <= n ; i ++ ) count += number0f2s ( i ) ; return count ; } document . write ( numberOf2sinRange ( 22 ) + " " ) ; document . write ( numberOf2sinRange ( 100 ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minToggle ( arr , n ) { let zero = new Array ( n + 1 ) ; zero [ 0 ] = 0 ; for ( let i = 1 ; i <= n ; ++ i ) { if ( arr [ i - 1 ] == 0 ) zero [ i ] = zero [ i - 1 ] + 1 ; else zero [ i ] = zero [ i - 1 ] ; } let ans = n ; for ( let i = 1 ; i <= n ; ++ i ) ans = Math . min ( ans , i - zero [ i ] + zero [ n ] - zero [ i ] ) ; return ans ; } let arr = [ 1 , 0 , 1 , 1 , 0 ] ; let n = arr . length ; document . write ( minToggle ( arr , n ) ) ;

Index/key variables: i, n
Iterator variables: i
Javascript program:
function check ( str ) { let n = str . length ; if ( ( str [ n - 1 ] - ' ' ) % 2 != 0 ) return false ; let digitSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) digitSum += ( str [ i ] - ' ' ) ; return ( digitSum % 3 == 0 ) ; } let str = " " ; if ( check ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: digitSum, i
Iterator variables: i
Javascript program:
let res = 0 ; function checkRecursive ( num , x , k , n ) { if ( x == 0 ) res ++ ; let r = Math . floor ( Math . pow ( num , 1.0 / n ) ) ; for ( let i = k + 1 ; i <= r ; i ++ ) { let a = x - Math . pow ( i , n ) ; if ( a >= 0 ) checkRecursive ( num , x - Math . pow ( i , n ) , i , n ) ; } return res ; } function check ( x , n ) { return checkRecursive ( x , x , 0 , n ) ; } document . write ( check ( 10 , 2 ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function nthPalindrome ( n , k ) { let temp = ( k & 1 ) != 0 ? parseInt ( k / 2 , 10 ) : ( parseInt ( k / 2 , 10 ) - 1 ) ; let palindrome = parseInt ( Math . pow ( 10 , temp ) , 10 ) ; palindrome += n - 1 ; document . write ( palindrome ) ; if ( ( k & 1 ) > 0 ) palindrome = parseInt ( palindrome / 10 , 10 ) ; while ( palindrome > 0 ) { document . write ( palindrome % 10 ) ; palindrome = parseInt ( palindrome / 10 , 10 ) ; } document . write ( " " + " " ) ; } let n = 6 , k = 5 ; document . write ( n + " " + k + " " ) ; nthPalindrome ( n , k ) ; n = 10 ; k = 6 ; document . write ( n + " " + k + " " ) ; nthPalindrome ( n , k ) ;

Accumulator variables: palindrome
Javascript program:
function findMax ( n , a , b , k , m ) { let arr = new Array ( n ) ; arr . fill ( 0 ) ; for ( let i = 0 ; i < m ; i ++ ) { let lowerbound = a [ i ] ; let upperbound = b [ i ] ; for ( let j = lowerbound ; j <= upperbound ; j ++ ) arr [ j ] += k [ i ] ; } let res = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) res = Math . max ( res , arr [ i ] ) ; return res ; } let n = 5 ; let a = [ 0 , 1 , 2 ] ; let b = [ 1 , 4 , 3 ] ; let k = [ 100 , 100 , 100 ] ; let m = a . length ; document . write ( " " + " " + findMax ( n , a , b , k , m ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function solve ( v ) { var res = [ ] ; var all3 = v [ 0 ] + v [ 1 ] + v [ 2 ] ; res . push ( all3 - v [ 1 ] * 2 ) ; res . push ( all3 - v [ 2 ] * 2 ) ; res . push ( all3 - v [ 0 ] * 2 ) ; return res ; } function findVertex ( xmid , ymid ) { var V1 = solve ( xmid ) ; var V2 = solve ( ymid ) ; for ( var i = 0 ; i < 3 ; i ++ ) { document . write ( V1 [ i ] + " " + V2 [ i ] + " " ) ; } } var xmid = [ 5 , 4 , 5 ] ; var ymid = [ 3 , 4 , 5 ] ; findVertex ( xmid , ymid ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nthElement ( a , b , n ) { let seq = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) seq . push ( a * i ) ; seq . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 1 , k = n ; i <= n && k > 0 ; i ++ ) { if ( ! seq . includes ( b * i ) ) { seq . push ( b * i ) ; seq . sort ( function ( a , b ) { return a - b } ) ; k -- ; } } return seq [ n - 1 ] ; } let a = 3 , b = 5 , n = 5 ; document . write ( nthElement ( a , b , n ) ) ;

Accumulator variables: i, k
Iterator variables: i
Javascript program:
function gcd ( a , b ) { return b > 0 ? gcd ( b , a % b ) : a ; } function countGCD ( L , R , g ) { L = parseInt ( ( L + g - 1 ) / g , 10 ) ; R = parseInt ( R / g , 10 ) ; let ans = 0 ; for ( let i = L ; i <= R ; i ++ ) for ( let j = L ; j <= R ; j ++ ) if ( gcd ( i , j ) == 1 ) ans ++ ; return ans ; } let L = 1 , R = 11 , g = 5 ; document . write ( countGCD ( L , R , g ) ) ;

Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let dig = [ 1 , 1 , 2 , 6 , 4 , 2 , 2 , 4 , 2 , 8 ] ; function lastNon0Digit ( n ) { if ( n < 10 ) return dig [ n ] ; if ( ( parseInt ( n / 10 , 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( parseInt ( n / 5 , 10 ) ) * dig [ n % 10 ] ) % 10 ; else return ( 4 * lastNon0Digit ( parseInt ( n / 5 , 10 ) ) * dig [ n % 10 ] ) % 10 ; } let n = 14 ; document . write ( lastNon0Digit ( n ) ) ;

Index/key variables: n
Javascript program:
function gcd ( a , b ) { if ( ( a % b ) == 0 ) return b ; return gcd ( b , a % b ) ; } function firstFactorialDivisibleNumber ( x ) { let new_x = x ; for ( i = 1 ; i < x ; i ++ ) { new_x = parseInt ( new_x / gcd ( i , new_x ) , 10 ) ; if ( new_x == 1 ) break ; } return i ; } let x = 16 ; document . write ( firstFactorialDivisibleNumber ( x ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sieve ( prime , n ) { for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == false ) for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = true ; } } function maxDigitInPrimes ( L , R ) { let prime = new Array ( R + 1 ) ; for ( let i = 0 ; i < R + 1 ; i ++ ) { prime [ i ] = false ; } sieve ( prime , R ) ; let freq = new Array ( 10 ) ; for ( let i = 0 ; i < 10 ; i ++ ) { freq [ i ] = 0 ; } let val ; for ( let i = L ; i <= R ; i ++ ) { if ( ! prime [ i ] ) { while ( p > 0 ) { freq [ p % 10 ] ++ ; p = Math . floor ( p / 10 ) ; } } } let max = freq [ 0 ] , ans = 0 ; for ( let j = 1 ; j < 10 ; j ++ ) { if ( max <= freq [ j ] ) { max = freq [ j ] ; ans = j ; } } return ans ; } let L = 1 , R = 20 ; document . write ( maxDigitInPrimes ( L , R ) ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, p
Iterator variables: i, j, p
Javascript program:
function simpleSieve ( ) { let arr = Array ( 1001 ) . fill ( true ) ; for ( let p = 2 ; p * p < 1001 ; p ++ ) { if ( arr [ p ] ) { for ( let i = p * 2 ; i < 1001 ; i = i + p ) arr [ i ] = false ; } } } function find_sphene ( N ) { var arr1 = Array ( 8 ) . fill ( 0 ) ; var count = 0 ; var j = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( N % i == 0 && count < 8 ) { count ++ ; arr1 [ j ++ ] = i ; } } if ( count == 8 && ( arr [ arr1 [ 1 ] ] && arr [ arr1 [ 2 ] ] && arr [ arr1 [ 3 ] ] ) ) return 1 ; return 0 ; } var n = 60 ; simpleSieve ( ) ; var ans = find_sphene ( n ) ; if ( ans == 1 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, p
Accumulator variables: count, i, j, p
Iterator variables: i, p
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function commDiv ( a , b ) { let n = gcd ( a , b ) ; let result = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) result += 1 ; else result += 2 ; } } return result ; } let a = 12 , b = 24 ; document . write ( commDiv ( a , b ) ) ;

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function spellsCount ( num ) { let n = num . length ; let result = 1 ; for ( let i = 0 ; i < n ; i ++ ) { let count = 1 ; while ( i < n - 1 && num [ i + 1 ] == num [ i ] ) { count ++ ; i ++ ; } result = result * Math . pow ( 2 , count - 1 ) ; } return result ; } let num = " " ; document . write ( spellsCount ( num ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function numSquareSum ( n ) { var squareSum = 0 ; while ( n != 0 ) { squareSum += ( n % 10 ) * ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return squareSum ; } function isHappynumber ( n ) { var slow , fast ; slow = fast = n ; do { slow = numSquareSum ( slow ) ; fast = numSquareSum ( numSquareSum ( fast ) ) ; } while ( slow != fast ) ; return ( slow == 1 ) ; } var n = 13 ; if ( isHappynumber ( n ) ) document . write ( n + " " ) ; else document . write ( n + " " ) ;

Accumulator variables: squareSum
Javascript program:
let allPrimes = [ ] ; function sieve ( n ) { let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) prime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( let p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) allPrimes . push ( p ) ; } function factorialDivisors ( n ) { let result = 1 ; for ( let i = 0 ; i < allPrimes . length ; i ++ ) { let p = allPrimes [ i ] ; let exp = 0 ; while ( p <= n ) { exp = exp + parseInt ( n / p , 10 ) ; p = p * allPrimes [ i ] ; } result = result * ( exp + 1 ) ; } return result ; } document . write ( factorialDivisors ( 6 ) ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; let k ; for ( k = 0 ; ( ( a b ) & 1 ) == 0 ; ++ k ) { a >>= 1 ; b >>= 1 ; } while ( ( a & 1 ) == 0 ) a >>= 1 ; do { while ( ( b & 1 ) == 0 ) b >>= 1 ; if ( a > b ) { let t = a ; a = b ; b = t ; } b = ( b - a ) ; } while ( b != 0 ) ; return a << k ; } let a = 34 , b = 17 ; document . write ( " " + gcd ( a , b ) ) ;

Iterator variables: k
Javascript program:
var one = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; var ten = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; function numToWords ( n , s ) { var str = " " ; if ( n > 19 ) { str += ten [ parseInt ( n / 10 ) ] + one [ n % 10 ] ; } else { str += one [ n ] ; } if ( n != 0 ) { str += s ; } return str ; } function convertToWords ( n ) { var out = " " ; out += numToWords ( parseInt ( n / 10000000 ) , " " ) ; out += numToWords ( parseInt ( ( n / 100000 ) % 100 ) , " " ) ; out += numToWords ( parseInt ( ( n / 1000 ) % 100 ) , " " ) ; out += numToWords ( parseInt ( ( n / 100 ) % 10 ) , " " ) ; if ( n > 100 && n % 100 > 0 ) { out += " " ; } out += numToWords ( parseInt ( n % 100 ) , " " ) ; return out ; } var n = 438237764 ; document . write ( convertToWords ( n ) ) ;

Index/key variables: n
Accumulator variables: out, str
Javascript program:
function countEvenSum ( a , n ) { let res = 0 ; let s = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] % 2 == 1 ) { s = n - i - 1 - s ; } else { s = s + 1 ; } res = res + s ; } return res ; } let arr = [ 1 , 2 , 2 , 3 , 4 , 1 ] ; let n = arr . length ; document . write ( " " + " " + countEvenSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function power ( x , y , p ) { while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function modInverse ( a , p ) { return power ( a , p - 2 , p ) ; } function modFact ( n , p ) { if ( p <= n ) return 0 ; let res = ( p - 1 ) ; for ( let i = n + 1 ; i < p ; i ++ ) res = ( res * modInverse ( i , p ) ) % p ; return res ; } let n = 25 , p = 29 ; document . write ( modFact ( n , p ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countWays ( n ) { for ( let i = 1 ; i < n ; i ++ ) for ( let j = i ; j < n ; j ++ ) for ( let k = j ; k < n ; k ++ ) for ( let l = k ; l < n ; l ++ ) if ( i + j + k + l == n ) counter ++ ; return counter ; } let n = 8 ; document . write ( countWays ( n ) ) ;

Accumulator variables: counter, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function pairAndSum ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) ans += arr [ i ] & arr [ j ] ; return ans ; } let arr = [ 5 , 10 , 15 ] ; let n = arr . length ; document . write ( pairAndSum ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function pairAndSum ( arr , n ) { for ( let i = 0 ; i < 32 ; i ++ ) { let k = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) != 0 ) k ++ ; } ans += ( 1 << i ) * ( k * ( k - 1 ) / 2 ) ; } return ans ; } let arr = [ 5 , 10 , 15 ] ; let n = arr . length ; document . write ( pairAndSum ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: ans, i, j, k
Iterator variables: i, j
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( let i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } isPrime ( 11 ) ? document . write ( " " + " " ) : document . write ( " " + " " ) ; isPrime ( 15 ) ? document . write ( " " + " " ) : document . write ( " " + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function computeTotient ( n ) { let phi = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) phi [ i ] = i ; for ( let p = 2 ; p <= n ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( let i = 2 * p ; i <= n ; i += p ) { phi [ i ] = parseInt ( phi [ i ] / p , 10 ) * ( p - 1 ) ; } } } for ( let i = 1 ; i <= n ; i ++ ) document . write ( " " + i + " " + phi [ i ] + " " ) ; } let n = 12 ; computeTotient ( n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function Euler_totient_function ( n ) { let result = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { let c = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { c ++ ; n = parseInt ( n / i ) ; } } if ( c > 0 ) { let power = Math . pow ( i , c - 1 ) ; let sm = Math . pow ( i , c - 1 ) * ( i - 1 ) ; result *= sm ; } } if ( n > 1 ) { result *= ( n - 1 ) ; } return result ; } for ( let i = 1 ; i < 13 ; i ++ ) { document . write ( " " + i + " " ) ; document . write ( Euler_totient_function ( i ) + " " ) ; }

Accumulator variables: c, i, result
Iterator variables: i
Javascript program:
function isPower ( n ) { let p ; if ( n <= 1 ) { return true ; } for ( let i = 2 ; i <= parseInt ( Math . sqrt ( n ) , 10 ) ; i ++ ) { p = ( Math . log ( n ) / Math . log ( i ) ) . toFixed ( 14 ) ; if ( ( Math . ceil ( p ) == Math . floor ( p ) ) && ( p > 1 ) ) { return true ; } } return false ; } for ( let i = 2 ; i < 100 ; i ++ ) { if ( isPower ( i ) ) document . write ( i + " " ) ; }

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumBetweenTwoKth ( arr , k1 , k2 ) { arr . sort ( function ( a , b ) { return a - b } ) ; var result = 0 ; for ( var i = k1 ; i < k2 - 1 ; i ++ ) result += arr [ i ] ; return result ; } var arr = [ 20 , 8 , 22 , 4 , 12 , 10 , 14 ] ; var k1 = 3 , k2 = 6 ; var n = arr . length ; document . write ( sumBetweenTwoKth ( arr , k1 , k2 ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function nthMagicNo ( n ) { let pow = 1 , answer = 0 ; while ( n != 0 ) { pow = pow * 5 ; if ( ( n & 1 ) == 1 ) answer += pow ; n >>= 1 ; } return answer ; } let n = 5 ; document . write ( " " + " " + nthMagicNo ( n ) ) ;

Accumulator variables: answer
Javascript program:
function XorSum ( A , B , N , M ) { let ans1 = 0 , ans2 = 0 ; for ( let i = 0 ; i < N ; i ++ ) ans1 = ans1 ^ A [ i ] ; for ( let i = 0 ; i < M ; i ++ ) ans2 = ans2 ^ B [ i ] ; return ( ans1 & ans2 ) ; } let A = [ 3 , 5 ] ; let B = [ 2 , 3 ] ; let N = A . length ; let M = B . length ; document . write ( XorSum ( A , B , N , M ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class TreeNode { constructor ( x ) { this . val = x ; this . left = null ; this . right = null ; } } function uniqueLevels ( root ) { let uniqueLevels = 0 ; let que = [ ] ; que . push ( root ) ; while ( que . length > 0 ) { let length = que . length ; let prefix_XOR = 0 ; let prefix_OR = 0 ; let flag = true ; for ( let i = 0 ; i < length ; i ++ ) { let temp = que [ 0 ] ; que . shift ( ) ; prefix_OR |= temp . val ; prefix_XOR ^= temp . val ; if ( prefix_XOR != prefix_OR ) flag = false ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; } if ( flag ) uniqueLevels += 1 ; } document . write ( uniqueLevels ) ; } let root = new TreeNode ( 5 ) ; root . left = new TreeNode ( 6 ) ; root . right = new TreeNode ( 9 ) ; root . left . left = new TreeNode ( 1 ) ; root . left . right = new TreeNode ( 4 ) ; root . right . right = new TreeNode ( 7 ) ; uniqueLevels ( root ) ;

Accumulator variables: i, prefix_OR, prefix_XOR, uniqueLevels
Iterator variables: i
Boolean variables: flag
Class/struct names: TreeNode
Javascript program:
var N = 5 var M = 2 function ConstructList ( Q ) { var xr = 0 ; var ans = [ ] ; for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( Q [ i ] [ 0 ] == 0 ) ans . push ( Q [ i ] [ 1 ] ^ xr ) ; else xr ^= Q [ i ] [ 1 ] ; } ans . push ( xr ) ; ans . sort ( ( a , b ) => a - b ) ; return ans ; } var Q = [ [ 0 , 6 ] , [ 0 , 3 ] , [ 0 , 2 ] , [ 1 , 4 ] , [ 1 , 5 ] ] ; var ans = ConstructList ( Q ) ; ans . forEach ( element => { document . write ( " " + element ) ; } ) ;

Index/key variables: i
Accumulator variables: i, xr
Iterator variables: i
Javascript program:
function build_num ( bit ) { let ans = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) if ( bit [ i ] > 0 ) ans += ( 1 << i ) ; return ans ; } function maximumOR ( arr , n , k ) { let bit = new Array ( 32 ) ; bit . fill ( 0 ) ; for ( let i = 0 ; i < k ; i ++ ) { for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) bit [ j ] ++ ; } } let max_or = build_num ( bit ) ; for ( let i = k ; i < n ; i ++ ) { for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i - k ] & ( 1 << j ) ) > 0 ) bit [ j ] -- ; } for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) bit [ j ] ++ ; } max_or = Math . max ( build_num ( bit ) , max_or ) ; } return max_or ; } let arr = [ 2 , 5 , 3 , 6 , 11 , 13 ] ; let k = 3 ; let n = arr . length ; document . write ( maximumOR ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j