dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function findgcd ( n , x , y ) { let g = gcd ( x , y ) ; for ( let i = 0 ; i < g ; i ++ ) document . write ( n ) ; } let n = 123 , x = 5 , y = 2 ; findgcd ( n , x , y ) ;

Accumulator variables: i
Iterator variables: i
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 /= gcd ( i , new_x ) ; if ( new_x == 1 ) break ; } return i ; } function countFactorialXNotY ( x , y ) { return ( firstFactorialDivisibleNumber ( y ) - firstFactorialDivisibleNumber ( x ) ) ; } let x = 15 , y = 25 ; document . write ( countFactorialXNotY ( x , y ) ) ;

Accumulator variables: i, new_x
Iterator variables: i
Javascript program:
function firstFactorialDivisibleNumber ( x ) { var fact = 1 ; for ( i = 1 ; i < x ; i ++ ) { fact = fact * i ; if ( fact % x == 0 ) break ; } return i ; } var x = 16 ; document . write ( firstFactorialDivisibleNumber ( x ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function SieveOfEratosthenes ( n , isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) isPrime [ i ] = false ; } } return false ; } function findPrimePair ( n ) { let isPrime = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { isPrime [ i ] = false ; } SieveOfEratosthenes ( n , isPrime ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPrime [ i ] && isPrime [ n - i ] ) { document . write ( i + " " + ( n - i ) ) ; return ; } } } let n = 74 ; findPrimePair ( n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function getFirstDigit ( x ) { while ( x >= 10 ) x /= 10 ; return x ; } function getCountWithSameStartAndEndFrom1 ( x ) { if ( x < 10 ) return x ; let tens = x / 10 ; let res = tens + 9 ; let firstDigit = getFirstDigit ( x ) ; let lastDigit = x % 10 ; if ( lastDigit < firstDigit ) res -- ; return res ; } function getCountWithSameStartAndEnd ( start , end ) { return getCountWithSameStartAndEndFrom1 ( end ) - getCountWithSameStartAndEndFrom1 ( start - 1 ) ; } let start = 5 , end = 40 ; document . write ( getCountWithSameStartAndEnd ( start , end ) ) ;

Accumulator variables: res, x
Javascript program:
function sieveOfEratosthenes ( n , isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) isPrime [ i ] = false ; } } } function rightTruPrime ( n ) { let isPrime = new Array ( n + 1 ) . fill ( false ) ; sieveOfEratosthenes ( n , isPrime ) ; while ( n != 0 ) { if ( isPrime [ n ] ) n = parseInt ( n / 10 ) ; else return false ; } return true ; } var n = 59399 ; if ( rightTruPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, n, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function SieveOfEratosthenes ( n , prime ) { 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 ; } } } function mersennePrimes ( n ) { let prime = [ ] ; SieveOfEratosthenes ( n , prime ) ; for ( let k = 2 ; ( ( 1 << k ) - 1 ) <= n ; k ++ ) { let num = ( 1 << k ) - 1 ; if ( prime [ ( num ) ] ) document . write ( num + " " ) ; } } let n = 31 ; document . write ( " " + " " + " " + n + " " ) ; mersennePrimes ( n ) ;

Index/key variables: i, p
Accumulator variables: i, k, p
Iterator variables: i, k, p
Javascript program:
function findSum ( N , K ) { let ans = 0 ; for ( let i = 1 ; i <= N ; i ++ ) ans += ( i % K ) ; return ans ; } let N = 10 , K = 2 ; document . write ( findSum ( N , K ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function findnum ( str ) { var n = str . length ; var count_after_dot = 0 ; let dot_seen = false ; var num = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) != ' ' ) { num = num * 10 + ( str . charAt ( i ) - ' ' ) ; if ( dot_seen == true ) count_after_dot ++ ; } else dot_seen = true ; } if ( dot_seen == false ) return 1 ; var dem = parseInt ( Math . pow ( 10 , count_after_dot ) ) ; return ( dem / gcd ( num , dem ) ) ; } let str = " " ; document . write ( findnum ( str ) ) ;

Accumulator variables: count_after_dot, i
Iterator variables: i
Boolean variables: dot_seen
Javascript program:
function divisible ( N , digit ) { let ans = 0 ; for ( let i = 0 ; i < N . length ; i ++ ) { ans = ( ans * 10 + ( N [ i ] - ' ' ) ) ; ans %= digit ; } return ( ans == 0 ) ; } function allDigits ( N ) { let divide = [ ] ; for ( let i = 0 ; i < divide . length ; i ++ ) { divide [ i ] = false ; } divide [ 1 ] = true ; for ( let digit = 2 ; digit <= 9 ; digit ++ ) { if ( divisible ( N , digit ) ) divide [ digit ] = true ; } let result = 0 ; for ( let i = 0 ; i < N . length ; i ++ ) { if ( divide [ N [ i ] - ' ' ] == true ) result ++ ; } return result ; } let N = " " ; document . write ( allDigits ( N ) ) ;

Index/key variables: digit, i
Accumulator variables: digit, i, result
Iterator variables: digit, i
Javascript program:
function countNums ( n , x , y ) { arr = Array ( n + 1 ) . fill ( false ) ; if ( x <= n ) arr [ x ] = true ; if ( y <= n ) arr [ y ] = true ; var result = 0 ; for ( i = Math . min ( x , y ) ; i <= n ; i ++ ) { if ( arr [ i ] ) { if ( i + x <= n ) arr [ i + x ] = true ; if ( i + y <= n ) arr [ i + y ] = true ; result ++ ; } } return result ; } var n = 15 , x = 5 , y = 7 ; document . write ( countNums ( n , x , y ) ) ;

Index/key variables: i, x, y
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function reverse ( x ) { var rev = 0 ; while ( x > 0 ) { rev = ( rev * 10 ) + x % 10 ; x = parseInt ( x / 10 ) ; } return rev ; } function printEmirp ( n ) { var prime = Array . from ( { length : n + 1 } , ( _ , i ) => true ) ; for ( p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] ) { var rev = reverse ( p ) ; if ( p != rev && rev <= n && prime [ rev ] ) { document . write ( p + " " + rev + " " ) ; prime [ rev ] = false ; } } } } var n = 100 ; printEmirp ( n ) ;

Index/key variables: i, p, rev
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function getSum ( n ) { let sum = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; else { sum = sum + i ; sum = sum + ( n / i ) ; } } } sum = sum - n ; return sum ; } function checkAbundant ( n ) { return ( getSum ( n ) > n ) ; } let k = checkAbundant ( 12 ) ? " " : " " ; document . write ( k ) ; k = checkAbundant ( 15 ) ? " " : " " ; document . write ( k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isPowerful ( n ) { while ( n % 2 == 0 ) { let power = 0 ; while ( n % 2 == 0 ) { n /= 2 ; power ++ ; } if ( power == 1 ) return false ; } for ( let factor = 3 ; factor <= Math . sqrt ( n ) ; factor += 2 ) { let power = 0 ; while ( n % factor == 0 ) { n = n / factor ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } if ( isPowerful ( 20 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isPowerful ( 27 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: factor, n, power
Iterator variables: factor
Javascript program:
function divisorsSum ( n ) { for ( let i = 1 ; i <= ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { sum = sum + i ; } { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } function isDeficient ( n ) { return ( divisorsSum ( n ) < ( 2 * n ) ) ; } if ( isDeficient ( 12 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isDeficient ( 15 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function iskaprekar ( n ) { if ( n == 1 ) return true ; let sq_n = n * n ; let count_digits = 0 ; while ( sq_n ) { count_digits ++ ; sq_n = parseInt ( sq_n / 10 ) ; } for ( let r_digits = 1 ; r_digits < count_digits ; r_digits ++ ) { let eq_parts = Math . pow ( 10 , r_digits ) ; if ( eq_parts == n ) continue ; let sum = parseInt ( ( sq_n1 / eq_parts ) + sq_n1 % eq_parts ) ; if ( sum == n ) return true ; } return false ; } document . write ( " " + " " ) ; for ( let i = 1 ; i < 10000 ; i ++ ) if ( iskaprekar ( i ) ) document . write ( i + " " ) ;

Accumulator variables: count_digits, i, r_digits
Iterator variables: i, r_digits
Javascript program:
function isKeith ( x ) { let terms = [ ] ; let temp = x ; while ( temp > 0 ) { terms . push ( temp % 10 ) ; temp = parseInt ( temp / 10 ) ; n ++ ; } terms = terms . reverse ( ) ; let next_term = 0 ; let i = n ; while ( next_term < x ) { next_term = 0 ; for ( let j = 1 ; j <= n ; j ++ ) next_term += terms [ i - j ] ; terms . push ( next_term ) ; i ++ ; } return ( next_term == x ) ; } isKeith ( 14 ) ? document . write ( " " ) : document . write ( " " ) ; isKeith ( 12 ) ? document . write ( " " ) : document . write ( " " ) ; isKeith ( 197 ) ? document . write ( " " ) : document . write ( " " ) ;

Accumulator variables: i, j, n, next_term
Iterator variables: j
Javascript program:
function evenFibSum ( limit ) { if ( limit < 2 ) return 0 ; let ef1 = 0 , ef2 = 2 ; let sum = ef1 + ef2 ; while ( ef2 <= limit ) { let ef3 = 4 * ef2 + ef1 ; if ( ef3 > limit ) break ; ef1 = ef2 ; ef2 = ef3 ; sum += ef2 ; } return sum ; } let limit = 400 ; document . write ( evenFibSum ( limit ) ) ;

Accumulator variables: sum
Javascript program:
function isPerfect ( n ) { var s = parseInt ( ( Math . sqrt ( n ) ) ) ; return ( s * s == n ) ; } function divisorsCount ( n ) { var count = 0 ; for ( var i = 1 ; i <= parseInt ( Math . sqrt ( n ) ) + 1 ; i ++ ) { if ( n % i == 0 ) { if ( parseInt ( n / i ) == i ) count += 1 ; else count += 2 ; } } return count ; } function kDivisors ( a , b , k ) { var count = 0 ; for ( var i = a ; i <= b ; i ++ ) { if ( isPerfect ( i ) ) { if ( divisorsCount ( i ) == k ) { count ++ ; } } } return count ; } var a = 2 , b = 49 , k = 3 ; document . write ( kDivisors ( a , b , k ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
let maxn = 10005 ; let INF = 999999 ; let smallest_prime = new Array ( maxn ) ; for ( let i = 0 ; i < maxn ; i ++ ) { smallest_prime [ i ] = 0 ; } let divisors = new Array ( maxn ) ; for ( let i = 0 ; i < maxn ; i ++ ) { divisors [ i ] = 0 ; } let segmentTree = new Array ( 4 * maxn ) ; for ( let i = 0 ; i < 4 * maxn ; i ++ ) { segmentTree [ i ] = 0 ; } function findSmallestPrimeFactors ( ) { for ( let i = 0 ; i < maxn ; i ++ ) smallest_prime [ i ] = INF ; for ( let i = 2 ; i < maxn ; i ++ ) { if ( smallest_prime [ i ] == INF ) { smallest_prime [ i ] = i ; for ( let j = i * i ; j < maxn ; j += i ) { if ( smallest_prime [ j ] > i ) smallest_prime [ j ] = i ; } } } } function buildDivisorsArray ( ) { for ( let i = 1 ; i < maxn ; i ++ ) { divisors [ i ] = 1 ; let n = i ; let p = smallest_prime [ i ] let k = 0 ; while ( n > 1 ) { n = Math . floor ( n / p ) ; k ++ ; if ( smallest_prime [ n ] != p ) { divisors [ i ] = divisors [ i ] * ( k + 1 ) ; k = 0 ; } p = smallest_prime [ n ] ; } } } function buildSegtmentTree ( node , a , b ) { if ( a == b ) { segmentTree [ node ] = divisors [ a ] ; return ; } buildSegtmentTree ( 2 * node , a , Math . floor ( ( a + b ) / 2 ) ) ; buildSegtmentTree ( ( 2 * node ) + 1 , Math . floor ( ( a + b ) / 2 ) + 1 , b ) ; segmentTree [ node ] = Math . max ( segmentTree [ 2 * node ] , segmentTree [ ( 2 * node ) + 1 ] ) ; } function query ( node , a , b , l , r ) { if ( l > b a > r ) return - 1 ; if ( a >= l && b <= r ) return segmentTree [ node ] ; return Math . max ( query ( 2 * node , a , Math . floor ( ( a + b ) / 2 ) , l , r ) , query ( 2 * node + 1 , Math . floor ( ( a + b ) / 2 ) + 1 , b , l , r ) ) ; } findSmallestPrimeFactors ( ) ; buildDivisorsArray ( ) ; buildSegtmentTree ( 1 , 1 , maxn - 1 ) ; document . write ( " " + " " + query ( 1 , 1 , maxn - 1 , 1 , 100 ) + " " ) ; document . write ( " " + " " + query ( 1 , 1 , maxn - 1 , 10 , 48 ) + " " ) ; document . write ( " " + " " + query ( 1 , 1 , maxn - 1 , 1 , 10 ) + " " ) ;

Index/key variables: a, i, j, n, node
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
let ma = new Map ( ) ; function primeFactorize ( a ) { for ( let i = 2 ; i * i <= a ; i += 2 ) { let cnt = 0 ; while ( a % i == 0 ) { cnt ++ ; a = parseInt ( a / i , 10 ) ; } ma . set ( i , cnt ) ; } if ( a > 1 ) { ma . set ( a , 1 ) ; } } function commDiv ( a , b ) { primeFactorize ( a ) ; let res = 1 ; ma . forEach ( ( values , keys ) => { let cnt = 0 ; let key = keys ; let value = values ; while ( b % key == 0 ) { b = parseInt ( b / key , 10 ) ; cnt ++ ; } res *= ( Math . min ( cnt , value ) + 1 ) ; } ) return res ; } let a = 12 , b = 24 ; document . write ( commDiv ( a , b ) ) ;

Accumulator variables: cnt, i, res
Iterator variables: i
Javascript program:
function findCountOfSolutions ( n , p ) { let ans = 0 ; for ( let x = 1 ; x < p ; x ++ ) { if ( ( x * x ) % p == 1 ) { let last = x + p * ( n / p ) ; if ( last > n ) last -= p ; ans += ( ( last - x ) / p + 1 ) ; } } return ans ; } let n = 10 ; let p = 5 ; document . write ( findCountOfSolutions ( n , p ) ) ;

Accumulator variables: ans, last, x
Iterator variables: x
Javascript program:
function kaprekarRec ( n , prev ) { if ( n == 0 ) return 0 ; prev = n ; var digits = Array . from ( { length : 4 } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < 4 ; i ++ ) { digits [ i ] = n % 10 ; n = parseInt ( n / 10 ) ; } digits . sort ( ) ; var asc = 0 ; for ( i = 0 ; i < 4 ; i ++ ) asc = asc * 10 + digits [ i ] ; digits . sort ( ) ; var desc = 0 ; for ( i = 3 ; i >= 0 ; i -- ) desc = desc * 10 + digits [ i ] ; var diff = Math . abs ( asc - desc ) ; if ( diff == prev ) return diff ; return kaprekarRec ( diff , prev ) ; } function kaprekar ( n ) { var prev = 0 ; return kaprekarRec ( n , prev ) ; } document . write ( kaprekar ( 1000 ) + " " ) ; document . write ( kaprekar ( 1112 ) + " " ) ; document . write ( kaprekar ( 9812 ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sqroot ( s ) { var pSq = 0 ; var N = 0 ; for ( i = parseInt ( s ) ; i > 0 ; i -- ) { for ( j = 1 ; j < i ; j ++ ) { if ( j * j == i ) { pSq = i ; N = j ; break ; } } if ( pSq > 0 ) break ; } var d = s - pSq ; var P = ( d / ( 2.0 * N ) ) ; var A = N + P ; var sqrt_of_s = A - ( ( P * P ) / ( 2.0 * A ) ) ; return sqrt_of_s ; } var num = 9.2345 ; var sqroot_of_num = sqroot ( num ) ; document . write ( " " + num + " " + ( Math . round ( sqroot_of_num * 100000.0 ) / 100000.0 ) . toFixed ( 6 ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function Modulo ( a , b ) { let mod = 0 ; for ( let i = 0 ; i < b . length ; i ++ ) mod = ( mod * 10 + b [ i ] - ' ' ) % a ; } function LastDigit ( a , b ) { let len_a = a . length ; let len_b = b . length ; if ( len_a == 1 && len_b == 1 && b [ 0 ] == ' ' && a [ 0 ] == ' ' ) return 1 ; if ( len_b == 1 && b [ 0 ] == ' ' ) return 1 ; if ( len_a == 1 && a [ 0 ] == ' ' ) return 0 ; exp = ( Modulo ( 4 , b ) == 0 ) ? 4 : Modulo ( 4 , b ) ; res = Math . pow ( a [ len_a - 1 ] - ' ' , exp ) ; return res % 10 ; } let a = " " ; let b = " " ; document . write ( LastDigit ( a , b ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let sum = [ ] ; function toInt ( x ) { return x - ' ' ; } function prepareSum ( s ) { sum [ 0 ] = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { sum [ i + 1 ] = sum [ i ] + toInt ( s [ i ] ) ; } } function query ( l , r ) { if ( ( sum [ r + 1 ] - sum [ l ] ) % 3 == 0 ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let n = " " ; prepareSum ( n ) ; query ( 0 , 1 ) ; query ( 1 , 2 ) ; query ( 3 , 6 ) ; query ( 0 , 10 ) ;

Index/key variables: i, l
Accumulator variables: i
Iterator variables: i
Javascript program:
function oneDigit ( num ) { return ( num >= 0 && num < 10 ) ; } function isPalUtil ( num , dupNum ) { if ( oneDigit ( num ) ) return ( num == ( dupNum ) % 10 ) ; if ( ! isPalUtil ( parseInt ( num / 10 ) , dupNum ) ) return false ; dupNum = parseInt ( dupNum / 10 ) ; return ( num % 10 == ( dupNum ) % 10 ) ; } function isPal ( num ) { if ( num < 0 ) num = - num ; return isPalUtil ( num , dupNum ) ; } function printPalPrimesLessThanN ( n ) { var prime = Array . from ( { length : n + 1 } , ( _ , i ) => true ) ; for ( p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] ) { for ( i = p * 2 ; i <= n ; i += p ) { prime [ i ] = false ; } } } for ( p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] && isPal ( p ) ) { document . write ( p + " " ) ; } } } var n = 100 ; document . write ( ' ' + n + ' ' ) ; printPalPrimesLessThanN ( n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function countPrimeFactors ( n ) { let count = 0 ; while ( n % 2 == 0 ) { n = n / 2 ; count ++ ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { n = n / i ; count ++ ; } } if ( n > 2 ) count ++ ; return ( count ) ; } function printKAlmostPrimes ( k , n ) { for ( let i = 1 , num = 2 ; i <= n ; num ++ ) { if ( countPrimeFactors ( num ) == k ) { document . write ( num + " " ) ; i ++ ; } } return ; } let n = 10 , k = 2 ; document . write ( " " + n + " " + k + " " + " " ) ; printKAlmostPrimes ( k , n ) ;

Accumulator variables: count, i, num
Iterator variables: i
Javascript program:
function findDigits ( n ) { if ( n < 0 ) return 0 ; if ( n <= 1 ) return 1 ; let digits = 0 ; for ( let i = 2 ; i <= n ; i ++ ) digits += Math . log10 ( i ) ; return Math . floor ( digits ) + 1 ; } document . write ( findDigits ( 1 ) + " " ) ; document . write ( findDigits ( 5 ) + " " ) ; document . write ( findDigits ( 10 ) + " " ) ; document . write ( findDigits ( 120 ) + " " ) ;

Accumulator variables: digits, i
Iterator variables: i
Javascript program:
function countEvenSum ( arr , n ) { let result = 0 ; for ( let i = 0 ; i <= n - 1 ; i ++ ) { let sum = 0 ; for ( let j = i ; j <= n - 1 ; j ++ ) { sum = sum + arr [ j ] ; if ( sum % 2 == 0 ) result ++ ; } } return ( result ) ; } let arr = [ 1 , 2 , 2 , 3 , 4 , 1 ] ; let n = arr . length ; document . write ( " " + " " ) ; document . write ( countEvenSum ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: i, j, result
Iterator variables: i, j
Javascript program:
function countEvenSum ( arr , n ) { let temp = [ 1 , 0 ] ; let result = 0 , sum = 0 ; for ( let i = 0 ; i <= n - 1 ; i ++ ) { sum = ( ( sum + arr [ i ] ) % 2 + 2 ) % 2 ; temp [ sum ] ++ ; } result = result + ( temp [ 0 ] * ( temp [ 0 ] - 1 ) / 2 ) ; result = result + ( temp [ 1 ] * ( temp [ 1 ] - 1 ) / 2 ) ; return ( result ) ; } let arr = [ 1 , 2 , 2 , 3 , 4 , 1 ] ; let n = arr . length ; document . write ( " " + " " + countEvenSum ( arr , n ) ) ;

Index/key variables: i, sum
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateSum ( n ) { let fibo = [ ] ; if ( n <= 0 ) return 0 ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; let sum = fibo [ 0 ] + fibo [ 1 ] ; for ( let i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += fibo [ i ] ; } return sum ; } let n = 4 ; document . write ( ` ${ calculateSum ( n ) } ` ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findCombinationsUtil ( arr , index , num , reducedNum ) { if ( reducedNum < 0 ) return ; if ( reducedNum == 0 ) { for ( let i = 0 ; i < index ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; return ; } let prev = ( index == 0 ) ? 1 : arr [ index - 1 ] ; for ( let k = prev ; k <= num ; k ++ ) { arr [ index ] = k ; findCombinationsUtil ( arr , index + 1 , num , reducedNum - k ) ; } } function findCombinations ( n ) { let arr = [ ] ; findCombinationsUtil ( arr , 0 , n , n ) ; } let n = 5 ; findCombinations ( n ) ;

Index/key variables: i, index
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
let z = 0 ; function pow1 ( base1 , exponent , modulus ) { let result = 1 ; base1 = base1 % modulus ; while ( exponent > 0 ) { if ( exponent % 2 == 1 ) result = ( result * base1 ) % modulus ; exponent = exponent >> 1 ; base1 = ( base1 * base1 ) % modulus ; } return result ; } function gcd ( a , b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } function order ( p , b ) { if ( gcd ( p , b ) != 1 ) { document . write ( " " + " " + " " ) ; return - 1 ; } let k = 3 ; while ( true ) { if ( pow1 ( b , k , p ) == 1 ) return k ; k ++ ; } } function convertx2e ( x ) { z = 0 ; while ( x % 2 == 0 ) { x /= 2 ; z ++ ; } return x ; } function STonelli ( n , p ) { if ( gcd ( n , p ) != 1 ) { System . out . prletln ( " " ) ; return - 1 ; } if ( pow1 ( n , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) { document . write ( " " + " " ) ; return - 1 ; } let s , e ; s = convertx2e ( p - 1 ) ; e = z ; let q ; for ( q = 2 ; ; q ++ ) { if ( pow1 ( q , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) break ; } let x = pow1 ( n , ( s + 1 ) / 2 , p ) ; let b = pow1 ( n , s , p ) ; let g = pow1 ( q , s , p ) ; let r = e ; while ( true ) { let m ; for ( m = 0 ; m < r ; m ++ ) { if ( order ( p , b ) == - 1 ) return - 1 ; if ( order ( p , b ) == Math . pow ( 2 , m ) ) break ; } if ( m == 0 ) return x ; x = ( x * pow1 ( g , Math . pow ( 2 , r - m - 1 ) , p ) ) % p ; g = pow1 ( g , Math . pow ( 2 , r - m ) , p ) ; b = ( b * g ) % p ; if ( b == 1 ) return x ; r = m ; } } let n = 2 ; let p = 113 ; let x = STonelli ( n , p ) ; if ( x == - 1 ) document . write ( " " + " " ) ; else document . write ( " " + n + " " + p + " " + x + " " ) ;

Accumulator variables: k, m, q, x, z
Iterator variables: m, q
Javascript program:
function isPerfectSquare ( n ) { for ( let sum = 0 , i = 1 ; sum < n ; i += 2 ) { sum += i ; if ( sum == n ) return true ; } return false ; } if ( isPerfectSquare ( 35 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isPerfectSquare ( 49 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Accumulator variables: i, sum
Iterator variables: sum
Javascript program:
function countDyckPaths ( n ) { let res = 1 ; for ( let i = 0 ; i < n ; ++ i ) { res *= ( 2 * n - i ) ; res /= ( i + 1 ) ; } return res / ( n + 1 ) ; } let n = 4 ; document . write ( " " + countDyckPaths ( n ) ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function isTriangular ( num ) { if ( num < 0 ) return false ; let sum = 0 ; for ( let n = 1 ; sum <= num ; n ++ ) { sum = sum + n ; if ( sum == num ) return true ; } return false ; } let n = 55 ; if ( isTriangular ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: n
Iterator variables: n
Javascript program:
function val ( c ) { if ( c >= ' ' . charCodeAt ( ) && c <= ' ' . charCodeAt ( ) ) return ( c - ' ' . charCodeAt ( ) ) ; else return ( c - ' ' . charCodeAt ( ) + 10 ) ; } function toDeci ( str , b_ase ) { let len = str . length ; let power = 1 ; let num = 0 ; let i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str [ i ] . charCodeAt ( ) ) >= b_ase ) { document . write ( " " ) ; return - 1 ; } num += val ( str [ i ] . charCodeAt ( ) ) * power ; power = power * b_ase ; } return num ; } let str = " " ; let b_ase = 16 ; document . write ( " " + str + " " + b_ase + " " + toDeci ( str , b_ase ) ) ;

Index/key variables: i
Accumulator variables: i, num
Iterator variables: i