dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function sum ( x , n ) { let i , total = 1.0 ; for ( i = 1 ; i <= n ; i ++ ) total = total + ( Math . pow ( x , i ) / i ) ; return total ; } let g ; let x = 2 ; let n = 5 ; document . write ( sum ( x , n ) . toFixed ( 2 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumSquare ( n ) { for ( i = 1 ; i * i <= n ; i ++ ) for ( j = 1 ; j * j <= n ; j ++ ) if ( i * i + j * j == n ) { document . write ( i + " " + j + " " + " " ) ; return true ; } return false ; } var n = 25 ; if ( sumSquare ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let M = 6 ; let N = 7 ; function preCompute ( mat , prefixCnt ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( mat [ i ] [ j ] == 0 ) { prefixCnt [ i ] [ j ] = 1 ; } else { prefixCnt [ i ] [ j ] = 0 ; } } } for ( let i = 0 ; i < M ; i ++ ) for ( let j = 1 ; j < N ; j ++ ) prefixCnt [ i ] [ j ] += prefixCnt [ i ] [ j - 1 ] ; for ( let i = 1 ; i < M ; i ++ ) for ( let j = 0 ; j < N ; j ++ ) prefixCnt [ i ] [ j ] += prefixCnt [ i - 1 ] [ j ] ; } function countQuery ( prefixCnt , pi , pj , qi , qj ) { let cnt = prefixCnt [ qi ] [ qj ] ; if ( pi > 0 ) cnt -= prefixCnt [ pi - 1 ] [ qj ] ; if ( pj > 0 ) cnt -= prefixCnt [ qi ] [ pj - 1 ] ; if ( pi > 0 && pj > 0 ) cnt += prefixCnt [ pi - 1 ] [ pj - 1 ] ; return cnt ; } function count0s ( mat , Q , sizeQ ) { let prefixCnt = new Array ( M ) ; for ( var i = 0 ; i < prefixCnt . length ; i ++ ) { prefixCnt [ i ] = new Array ( 2 ) ; } preCompute ( mat , prefixCnt ) ; for ( let i = 0 ; i < sizeQ ; i ++ ) { document . write ( countQuery ( prefixCnt , Q [ i ] [ 0 ] , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , Q [ i ] [ 3 ] ) + " " ) ; } } let mat = [ [ 0 , 1 , 0 , 1 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 , 1 , 0 , 1 ] , [ 1 , 1 , 0 , 0 , 1 , 1 , 0 ] , [ 1 , 1 , 1 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 0 , 1 , 1 , 0 , 1 ] ] ; let Q = [ [ 0 , 1 , 3 , 2 ] , [ 2 , 2 , 4 , 5 ] , [ 4 , 3 , 5 , 6 ] ] ; let sizeQ = Q . length ; count0s ( mat , Q , sizeQ ) ;

Index/key variables: i, j, qi, qj
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function check ( a , b ) { var c = 0 ; while ( a != 0 ) { c = c + a % 10 ; a = parseInt ( a / 10 ) ; } return ( c == b ) ; } function root ( n ) { var found = false ; var mx = 1E18 ; for ( i = 0 ; i <= 90 ; i ++ ) { var s = i * i + 4 * n ; var sq = Math . sqrt ( s ) ; if ( sq * sq == s && check ( ( sq - i ) / 2 , i ) ) { found = true ; mx = Math . min ( mx , ( sq - i ) / 2 ) ; } } if ( found ) return mx ; else return - 1 ; } var n = 110 ; document . write ( root ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Boolean variables: found
Javascript program:
function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function coprime ( a , b ) { return ( __gcd ( a , b ) == 1 ) ; } function pairSum ( n ) { let mid = Math . floor ( n / 2 ) ; for ( let i = mid ; i >= 1 ; i -- ) { if ( coprime ( i , n - i ) == true ) { document . write ( i + " " + ( n - i ) ) ; break ; } } } let n = 11 ; pairSum ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function modBigNumber ( num , m ) { let vec = [ ] ; let x = 0 ; let mod = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { digit = num [ i ] - ' ' ; mod = mod * 10 + digit ; quo = parseInt ( mod / m ) ; vec [ x ++ ] = quo ; mod = mod % m ; } document . write ( " " + mod + " " ) ; document . write ( " " ) ; let zeroflag = 0 ; for ( let i = 0 ; i < x ; i ++ ) { if ( vec [ i ] == 0 && zeroflag == 0 ) continue ; zeroflag = 1 ; document . write ( vec [ i ] ) ; } return ; } let num = " " ; let m = 487 ; modBigNumber ( num , m ) ;

Index/key variables: i
Accumulator variables: i, x
Iterator variables: i
Javascript program:
var N = 1000000 ; var fourDiv = Array ( N + 1 ) . fill ( false ) ; function fourDistinctFactors ( ) { var primeAll = Array ( N + 1 ) . fill ( false ) ; for ( var p = 2 ; p * p <= N ; p ++ ) { if ( primeAll [ p ] == false ) { for ( var i = p * 2 ; i <= N ; i += p ) primeAll [ i ] = true ; } } var prime = [ ] ; for ( var p = 2 ; p <= N ; p ++ ) if ( ! primeAll [ p ] ) prime . push ( p ) ; for ( var i = 0 ; i < prime . length ; ++ i ) { var p = prime [ i ] ; if ( p * p * p <= N ) fourDiv [ p * p * p ] = true ; for ( var j = i + 1 ; j < prime . length ; ++ j ) { var q = prime [ j ] ; if ( p * q > N ) break ; fourDiv [ p * q ] = true ; } } } fourDistinctFactors ( ) ; var num = 10 ; if ( fourDiv [ num ] ) document . write ( " " ) ; else document . write ( " " ) ; num = 12 ; if ( fourDiv [ num ] ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, num, p
Accumulator variables: i, p
Iterator variables: i, j, p
Javascript program:
function Cholesky_Decomposition ( matrix , n ) { var lower = Array ( n ) . fill ( 0 ) . map ( x => Array ( n ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { var sum = 0 ; if ( j == i ) { for ( var k = 0 ; k < j ; k ++ ) sum += parseInt ( Math . pow ( lower [ j ] [ k ] , 2 ) ) ; lower [ j ] [ j ] = parseInt ( Math . sqrt ( matrix [ j ] [ j ] - sum ) ) ; } else { for ( var k = 0 ; k < j ; k ++ ) sum += ( lower [ i ] [ k ] * lower [ j ] [ k ] ) ; lower [ i ] [ j ] = ( matrix [ i ] [ j ] - sum ) / lower [ j ] [ j ] ; } } } document . write ( " " ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) document . write ( lower [ i ] [ j ] + " " ) ; for ( var j = 0 ; j < n ; j ++ ) document . write ( lower [ j ] [ i ] + " " ) ; document . write ( ' ' ) ; } } var n = 3 ; var matrix = [ [ 4 , 12 , - 16 ] , [ 12 , 37 , - 43 ] , [ - 16 , - 43 , 98 ] ] ; Cholesky_Decomposition ( matrix , n ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Javascript program:
var MAX = 10 ; function findValue ( arr , n ) { var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) ans = Math . max ( ans , Math . abs ( arr [ i ] - arr [ j ] ) + Math . abs ( i - j ) ) ; return ans ; } var arr = [ 1 , 2 , 3 , 1 ] ; var n = arr . length ; document . write ( findValue ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findValue ( arr , n ) { let a = new Array ( n ) ; let b = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = ( arr [ i ] + i ) ; b [ i ] = ( arr [ i ] - i ) ; } let x = a [ 0 ] , y = a [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) x = a [ i ] ; if ( a [ i ] < y ) y = a [ i ] ; } let ans1 = ( x - y ) ; x = b [ 0 ] ; y = b [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( b [ i ] > x ) x = b [ i ] ; if ( b [ i ] < y ) y = b [ i ] ; } let ans2 = ( x - y ) ; return Math . max ( ans1 , ans2 ) ; } let arr = [ 1 , 2 , 3 , 1 ] ; let n = arr . length ; document . write ( findValue ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countsubarray ( array , n , k ) { var count = 0 ; var i , j , mul ; for ( i = 0 ; i < n ; i ++ ) { if ( array [ i ] < k ) count ++ ; mul = array [ i ] ; for ( j = i + 1 ; j < n ; j ++ ) { mul = mul * array [ j ] ; if ( mul < k ) count ++ ; else break ; } } return count ; } var array = [ 1 , 2 , 3 , 4 ] ; var k = 10 ; var size = array . length ; var count = countsubarray ( array , size , k ) ; document . write ( count ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function noOfFactors ( N ) { if ( N == 1 ) return 1 ; let count = 0 ; let ans = 1 ; while ( N % 2 == 0 ) { count ++ ; N = parseInt ( N / 2 ) ; } ans *= ( parseInt ( count / 3 ) + 1 ) ; for ( let i = 3 ; i * i <= N ; i = i + 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = parseInt ( N / i ) ; } ans *= ( parseInt ( count / 3 ) + 1 ) ; } return ans ; } let N = 216 ; document . write ( noOfFactors ( N ) ) ;

Accumulator variables: ans, count
Iterator variables: i
Javascript program:
var MAX = 1000001 ; var factor = [ ] ; function generatePrimeFactors ( ) { factor [ 1 ] = 1 ; for ( i = 2 ; i < MAX ; i ++ ) factor [ i ] = i ; for ( i = 4 ; i < MAX ; i += 2 ) factor [ i ] = 2 ; for ( i = 3 ; i * i < MAX ; i ++ ) { if ( factor [ i ] == i ) { for ( j = i * i ; j < MAX ; j += i ) { if ( factor [ j ] == j ) factor [ j ] = i ; } } } } function calculateNoOFactors ( n ) { if ( n == 1 ) return 1 ; var ans = 1 ; var dup = factor [ n ] ; var c = 1 ; var j = n / factor [ n ] ; while ( j != 1 ) { if ( factor [ j ] == dup ) c += 1 ; else { dup = factor [ j ] ; ans = ans * ( c + 1 ) ; c = 1 ; } j = j / factor [ j ] ; } ans = ans * ( c + 1 ) ; return ans ; } factor = Array ( MAX ) . fill ( 0 ) ; factor [ 0 ] = 0 ; generatePrimeFactors ( ) ; var a = [ 10 , 30 , 100 , 450 , 987 ] ; var q = a . length ; for ( i = 0 ; i < q ; i ++ ) document . write ( calculateNoOFactors ( a [ i ] ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function digit_product_Sum ( N ) { var a = [ ... Array ( N ) ] ; var product = 1 ; a [ 0 ] = 1 ; for ( var i = 1 ; i <= N ; i ++ ) { product = parseInt ( a [ i - 1 ] / 10 ) ; if ( product == 0 ) product = 1 ; else product = a [ i - 1 ] % 10 ; var val = parseInt ( a [ i - 1 ] / 10 ) ; if ( val == 0 ) val = a [ i - 1 ] ; a [ i ] = a [ i - 1 ] + val * product ; } for ( var i = 0 ; i < N ; i ++ ) document . write ( a [ i ] + " " ) ; } var N = 10 ; digit_product_Sum ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function geometricMean ( arr , n ) { let product = 1 ; for ( let i = 0 ; i < n ; i ++ ) product = product * arr [ i ] ; let gm = Math . pow ( product , 1 / n ) ; return gm ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ; let n = arr . length ; document . write ( geometricMean ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const SIZE = 4 ; function productOfSingelDgt ( n ) { if ( n >= 0 && n <= 9 ) return true ; var prime = [ 2 , 3 , 5 , 7 ] ; for ( i = 0 ; i < SIZE && n > 1 ; i ++ ) while ( n % prime [ i ] == 0 ) n = n / prime [ i ] ; return ( n == 1 ) ; } var n = 24 ; if ( productOfSingelDgt ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxPrimefactorNum ( N ) { if ( N < 2 ) return 0 ; arr = Array . from ( { length : N + 1 } , ( _ , i ) => false ) ; var prod = 1 , res = 0 ; for ( var p = 2 ; p * p <= N ; p ++ ) { if ( arr [ p ] == false ) { for ( var i = p * 2 ; i <= N ; i += p ) arr [ i ] = true ; prod *= p ; if ( prod > N ) return res ; res ++ ; } } return res ; } var N = 500 ; document . write ( maxPrimefactorNum ( N ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, prod, res
Iterator variables: i, p
Javascript program:
let n = 8 ; let range = 12 ; for ( let i = 1 ; i <= range ; ++ i ) document . write ( n + " " + i + " " + n * i + " " ) ;

Iterator variables: i
Javascript program:
function isPalindrome ( n ) { var divisor = 1 ; while ( parseInt ( n / divisor ) >= 10 ) divisor *= 10 ; while ( n != 0 ) { var leading = parseInt ( n / divisor ) ; var trailing = n % 10 ; if ( leading != trailing ) return false ; n = parseInt ( ( n % divisor ) / 10 ) ; divisor = divisor / 100 ; } return true ; } if ( isPalindrome ( 1001 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: divisor
Javascript program:
function printDemlo ( str ) { let len = str . length ; let res = " " ; for ( let i = 1 ; i <= len ; i ++ ) res += i . toString ( ) ; for ( let i = len - 1 ; i >= 1 ; i -- ) res += i . toString ( ) ; return res ; } let str = " " ; document . write ( printDemlo ( str ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function NumberofTimes ( str ) { var temporary_sum = 0 , count = 0 ; while ( str . length > 1 ) { temporary_sum = 0 ; for ( i = 0 ; i < str . length ; i ++ ) temporary_sum += ( str . charAt ( i ) - ' ' ) ; str = temporary_sum + " " ; count ++ ; } return count ; } var s = " " ; document . write ( NumberofTimes ( s ) ) ;

Accumulator variables: count, i, temporary_sum
Iterator variables: i
Javascript program:
function calculateLeaps ( n ) { if ( n == 0 n == 1 ) { return 1 ; } else { let leaps = 0 ; for ( let i = 0 ; i < n ; i ++ ) leaps += calculateLeaps ( i ) ; return leaps ; } } document . write ( calculateLeaps ( 4 ) ) ;

Accumulator variables: i, leaps
Iterator variables: i
Javascript program:
function power ( x , y , p ) { var res = 1 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return parseInt ( res ) ; } function printLastKDigits ( a , b , k ) { document . write ( " " + k + " " + a + " " + b + " " ) ; var temp = 1 ; for ( i = 1 ; i <= k ; i ++ ) temp *= 10 ; temp = power ( a , b , temp ) ; for ( i = 0 ; i < k - temp . toString ( ) . length ; i ++ ) document . write ( 0 ) ; if ( temp != 0 ) document . write ( temp ) ; } var a = 11 ; var b = 3 ; var k = 2 ; printLastKDigits ( a , b , k ) ;

Accumulator variables: i, temp
Iterator variables: i
Javascript program:
function totalDigits ( n ) { var number_of_digits = 0 ; for ( var i = 1 ; i <= n ; i *= 10 ) number_of_digits += ( n - i + 1 ) ; return number_of_digits ; } var n = 13 ; document . write ( totalDigits ( n ) ) ;

Accumulator variables: i, number_of_digits
Iterator variables: i
Javascript program:
function numbersWith3Divisors ( n ) { let prime = new Array ( n + 1 ) ; prime . fill ( true ) ; prime [ 0 ] = prime [ 1 ] = 0 ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } document . write ( " " + " " ) ; for ( let i = 0 ; i * i <= n ; i ++ ) if ( prime [ i ] ) document . write ( i * i + " " ) ; } let n = 96 ; numbersWith3Divisors ( n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function decToHexa ( n ) { var hexaDeciNum = Array . from ( { length : 100 } , ( _ , i ) => 0 ) ; var i = 0 ; while ( n != 0 ) { var temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = String . fromCharCode ( temp + 48 ) ; i ++ ; } else { hexaDeciNum [ i ] = String . fromCharCode ( temp + 55 ) ; i ++ ; } n = parseInt ( n / 16 ) ; } for ( j = i - 1 ; j >= 0 ; j -- ) document . write ( hexaDeciNum [ j ] ) ; } var n = 2545 ; decToHexa ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function decToBinary ( n ) { let binaryNum = new Array ( 32 ) ; let i = 0 ; while ( n > 0 ) { binaryNum [ i ] = n % 2 ; n = Math . floor ( n / 2 ) ; i ++ ; } for ( let j = i - 1 ; j >= 0 ; j -- ) document . write ( binaryNum [ j ] ) ; } let n = 17 ; decToBinary ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function flipSign ( a ) { var neg = 0 ; var tmp = a < 0 ? 1 : - 1 ; while ( a != 0 ) { neg += tmp ; a += tmp ; } return neg ; } function areDifferentSign ( a , b ) { return ( ( a < 0 && b > 0 ) || ( a > 0 && b < 0 ) ) ; } function sub ( a , b ) { return a + flipSign ( b ) ; } function mul ( a , b ) { if ( a < b ) return mul ( b , a ) ; var sum = 0 ; for ( i = Math . abs ( b ) ; i > 0 ; i -- ) sum += a ; if ( b < 0 ) sum = flipSign ( sum ) ; return sum ; } function division ( a , b ) { if ( b == 0 ) throw new ArithmeticException ( ) ; var quotient = 0 , dividend ; var divisor = flipSign ( Math . abs ( b ) ) ; for ( dividend = Math . abs ( a ) ; dividend >= Math . abs ( divisor ) ; dividend += divisor ) quotient ++ ; if ( areDifferentSign ( a , b ) ) quotient = flipSign ( quotient ) ; return quotient ; } document . write ( " " + sub ( 4 , - 2 ) ) ; document . write ( " " + mul ( - 9 , 6 ) ) ; try { document . write ( " " + division ( 8 , 2 ) ) ; } catch ( e ) { document . write ( " " ) ; }

Accumulator variables: a, dividend, i, neg, quotient, sum
Iterator variables: dividend, i
Javascript program:
function numOfCombinations ( arr , N ) { let C = [ 0 , 0 , 0 ] ; for ( let i = 0 ; i < N ; ++ i ) ++ C [ arr [ i ] % 3 ] ; return C [ 1 ] * C [ 2 ] + C [ 0 ] * ( C [ 0 ] - 1 ) / 2 + C [ 0 ] * ( C [ 0 ] - 1 ) * ( C [ 0 ] - 2 ) / 6 + C [ 1 ] * ( C [ 1 ] - 1 ) * ( C [ 1 ] - 2 ) / 6 + C [ 2 ] * ( C [ 2 ] - 1 ) * ( C [ 2 ] - 2 ) / 6 + C [ 0 ] * C [ 1 ] * C [ 2 ] ; } let arr1 = [ 1 , 5 , 7 , 2 , 9 , 14 ] ; document . write ( numOfCombinations ( arr1 , 6 ) + " " ) ; let arr2 = [ 3 , 6 , 9 , 12 ] ; document . write ( numOfCombinations ( arr2 , 4 ) + " " ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function printUnique ( l , r ) { for ( let i = l ; i <= r ; i ++ ) { let num = i ; let visited = new Array ( 10 ) ; while ( num ) { if ( visited [ num % 10 ] ) break ; visited [ num % 10 ] = true ; num = Math . floor ( num / 10 ) ; } if ( num == 0 ) document . write ( i + " " ) ; } } let l = 1 , r = 20 ; printUnique ( l , r ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinZero ( p ) { let first = 1 ; let second = 1 ; let number = 2 ; let next = 1 ; while ( next ) { next = ( first + second ) % p ; first = second ; second = next ; number ++ ; } return number ; } let p = 7 ; document . write ( " " , findMinZero ( p ) + " " ) ;

Accumulator variables: number
Javascript program:
function printCubes ( a , b ) { for ( let i = a ; i <= b ; i ++ ) { for ( let j = 1 ; j * j * j <= i ; j ++ ) { if ( j * j * j == i ) { document . write ( j * j * j + " " ) ; break ; } } } } let a = 1 ; let b = 100 ; document . write ( " " ) ; printCubes ( a , b ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printBinary ( num ) { if ( num >= 1 num <= 0 ) return " " ; let binary = " " ; let frac = 0.5 ; binary += " " ; while ( num > 0 ) { if ( binary . length >= 32 ) return " " ; if ( num >= frac ) { binary += " " ; num -= frac ; } else binary += " " ; frac = frac / 2 ; } return binary ; } let num1 = 0.625 ; let output = printBinary ( num1 ) ; document . write ( " " + output + " " + " " ) ; let num2 = 0.72 ; output = printBinary ( num2 ) ; document . write ( " " + output + " " ) ;

Accumulator variables: binary, num
Javascript program:
function firstkdigits ( n , k ) { let product = 1 ; for ( let i = 0 ; i < n ; i ++ ) product *= n ; while ( Math . floor ( product / Math . pow ( 10 , k ) ) != 0 ) product = Math . floor ( product / 10 ) ; return product ; } let n = 15 ; let k = 4 ; document . write ( firstkdigits ( n , k ) ) ;

Accumulator variables: i, product
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 % 9 == 0 ) ; } let str = " " ; let x = check ( str ) ? " " : " " ; document . write ( x ) ;

Index/key variables: i
Accumulator variables: digitSum, i
Iterator variables: i
Javascript program:
function getTotalXorOfSubarrayXors ( arr , N ) { let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = i ; j < N ; j ++ ) for ( let k = i ; k <= j ; k ++ ) res = res ^ arr [ k ] ; return res ; } let arr = [ 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; document . write ( getTotalXorOfSubarrayXors ( arr , N ) ) ;

Index/key variables: k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function getTotalXorOfSubarrayXors ( arr , N ) { let res = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let freq = ( i + 1 ) * ( N - i ) ; if ( freq % 2 == 1 ) res = res ^ arr [ i ] ; } return res ; } let arr = [ 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; document . write ( getTotalXorOfSubarrayXors ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function findGCD ( arr , n ) { let result = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { result = gcd ( arr [ i ] , result ) ; if ( result == 1 ) { return 1 ; } } return result ; } let arr = [ 2 , 4 , 6 , 8 , 16 ] ; let n = arr . length ; document . write ( findGCD ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function divSum ( num ) { let result = 0 ; for ( let i = 1 ; i * i <= num ; ++ i ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return result ; } function isSuperPerfect ( n ) { let n1 = divSum ( n ) ; return ( 2 * n == divSum ( n1 ) ) ; } let n = 16 ; document . write ( ( isSuperPerfect ( n ) ? " " : " " ) + " " ) ; n = 6 ; document . write ( ( isSuperPerfect ( n ) ? " " : " " ) + " " ) ;

Accumulator variables: result
Iterator variables: i
Javascript program:
function isRefactorableNumber ( n ) { let divCount = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; ++ i ) { if ( n % i == 0 ) { if ( n / i == i ) ++ divCount ; else divCount += 2 ; } } return n % divCount == 0 ; } let n = 8 ; if ( isRefactorableNumber ( n ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; n = 14 ; if ( isRefactorableNumber ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: divCount
Iterator variables: i
Javascript program:
function isPerfectSquare ( n ) { let sq = Math . sqrt ( n ) ; return ( n == sq * sq ) ; } function countPerfectDivisors ( n ) { let count = 0 ; for ( let i = 1 ; i * i <= n ; ++ i ) { if ( n % i == 0 ) { if ( isPerfectSquare ( i ) ) ++ count ; if ( n / i != i && isPerfectSquare ( n / i ) ) ++ count ; } } return count ; } let n = 16 ; document . write ( " " + " " + n ) ; document . write ( " " + countPerfectDivisors ( n ) + " " ) ; n = 12 ; document . write ( " " + " " + n ) ; document . write ( " " + countPerfectDivisors ( n ) ) ;

Iterator variables: i
Javascript program:
function nearestGcd ( arr , n ) { for ( let i = 0 ; i < n ; ++ i ) { let closest = - 1 ; for ( let j = i - 1 , k = i + 1 ; j > 0 k <= n ; -- j , ++ k ) { if ( j >= 0 && __gcd ( arr [ i ] , arr [ j ] ) > 1 ) { closest = j + 1 ; break ; } if ( k < n && __gcd ( arr [ i ] , arr [ k ] ) > 1 ) { closest = k + 1 ; break ; } } document . write ( closest + " " ) ; } } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } let arr = [ 2 , 9 , 4 , 3 , 13 ] ; let n = arr . length ; nearestGcd ( arr , n ) ;

Index/key variables: i, j, k
Iterator variables: i, j
Javascript program:
let MAX = 100001 ; let prime = new Array ( MAX + 1 ) ; let countdiv = new Array ( MAX + 1 ) ; for ( let i = 0 ; i < MAX + 1 ; i ++ ) { prime [ i ] = 0 ; countdiv [ i ] = 0 ; } function SieveOfEratosthenes ( ) { for ( let i = 2 ; i * i <= MAX ; ++ i ) { if ( prime [ i ] == 0 ) for ( let j = i * 2 ; j <= MAX ; j += i ) prime [ j ] = i ; } for ( let i = 1 ; i < MAX ; ++ i ) if ( prime [ i ] == 0 ) prime [ i ] = i ; } function largestGCDSubsequence ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; ++ i ) { let element = arr [ i ] ; while ( element > 1 ) { let div = prime [ element ] ; ++ countdiv [ div ] ; ans = Math . max ( ans , countdiv [ div ] ) ; while ( element % div == 0 ) element /= div ; } } return ans ; } SieveOfEratosthenes ( ) ; let arr = [ 10 , 15 , 7 , 25 , 9 , 35 ] ; let size = arr . length ; document . write ( largestGCDSubsequence ( arr , size ) ) ;

Index/key variables: div, element, i, j
Accumulator variables: element, i, j
Iterator variables: i, j
Javascript program:
function countOfBinaryNumberLessThanN ( N ) { var q = [ ] ; q . push ( 1 ) ; var cnt = 0 ; var t ; while ( q . length > 0 ) { t = q . pop ( ) ; if ( t <= N ) { cnt ++ ; q . push ( t * 10 ) ; q . push ( t * 10 + 1 ) ; } } return cnt ; } var N = 200 ; document . write ( countOfBinaryNumberLessThanN ( N ) + " " ) ;

Accumulator variables: cnt
Javascript program:
function sumofproduct ( n ) { var ans = 0 ; for ( x = 1 ; x <= n ; x ++ ) { var y = parseInt ( n / x ) ; ans += ( y * x ) ; } return ans ; } var n = 10 ; document . write ( sumofproduct ( n ) ) ;

Accumulator variables: ans, x
Iterator variables: x