dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function distinct ( arr , n ) { var mpp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { mpp . set ( arr [ i ] , 1 ) ; } return mpp . size ; } function maxSubSum ( arr , n , k , totalDistinct ) { if ( k > n ) return 0 ; var maxm = 0 , sum = 0 ; for ( var i = 0 ; i < n - k + 1 ; i ++ ) { sum = 0 ; var st = new Set ( ) ; for ( var j = i ; j < i + k ; j ++ ) { sum += arr [ j ] ; st . add ( arr [ j ] ) ; } if ( st . size == totalDistinct ) maxm = Math . max ( sum , maxm ) ; } return maxm ; } var arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ] ; var K = 6 ; var N = arr . length ; var totalDistinct = distinct ( arr , N ) ; document . write ( maxSubSum ( arr , N , K , totalDistinct ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function distinct ( arr , N ) { var st = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { st . add ( arr [ i ] ) ; } return st . size ; } function maxSubarraySumUtil ( arr , N , K , totalDistinct ) { if ( K > N ) return 0 ; var mx = 0 ; var sum = 0 ; var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) sum += arr [ i ] ; if ( i >= K ) { if ( mp . has ( arr [ i - K ] ) ) mp . set ( arr [ i - K ] , mp . get ( arr [ i - K ] ) - 1 ) sum -= arr [ i - K ] ; if ( mp . has ( arr [ i - K ] ) && mp . get ( arr [ i - K ] ) == 0 ) mp . delete ( arr [ i - K ] ) ; } if ( mp . size == totalDistinct ) mx = Math . max ( mx , sum ) ; } return mx ; } function maxSubarraySum ( arr , K ) { var N = arr . length ; var totalDistinct = distinct ( arr , N ) ; document . write ( maxSubarraySumUtil ( arr , N , K , totalDistinct ) ) ; } var arr = [ 7 , 7 , 2 , 4 , 2 , 7 , 4 , 6 , 6 , 6 ] ; var K = 6 ; maxSubarraySum ( arr , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countAPs ( N ) { let count = 0 ; for ( let i = 1 ; i * i <= 2 * N ; i ++ ) { let res = 2 * N ; if ( res % i == 0 ) { let op = res / i - i + 1 ; if ( op % 2 == 0 ) { count ++ ; } if ( i * i != res && ( i - res / i + 1 ) % 2 == 0 ) { count ++ ; } } } document . write ( count - 1 ) ; } let N = 963761198400 ; countAPs ( N ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
var sieve = Array . from ( { length : 105 } , ( _ , i ) => 0 ) ; function buildSieve ( ) { for ( i = 2 ; i < 100 ; i ++ ) sieve [ i ] = 1 ; for ( i = 2 ; i < 100 ; i ++ ) { if ( sieve [ i ] == 1 ) { for ( j = i * i ; j < 100 ; j += i ) sieve [ j ] = 0 ; } } } function isAnyPrime ( first , last ) { var num1 = first * 10 + last ; var num2 = last * 10 + first ; if ( sieve [ num1 ] == 1 sieve [ num2 ] == 1 ) return true ; else return false ; } function performQueries ( q ) { for ( i = 0 ; i < q . length ; i ++ ) { var A = q [ i ] ; var last = A % 10 ; var first ; while ( A >= 10 ) A = A / 10 ; first = A ; if ( isAnyPrime ( first , last ) ) document . write ( " " ) ; else document . write ( " " ) ; } } var q = [ 30 , 66 ] ; buildSieve ( ) ; performQueries ( q ) ;

Index/key variables: i, j, num1, num2
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function oddDivisor ( N ) { var X = N ; var i ; while ( N % 2 == 0 ) { N /= 2 ; } for ( i = 3 ; i * i <= X ; i += 2 ) { if ( N % i == 0 ) { return " " ; } } if ( N != X ) return " " ; return " " ; } var N = 10 ; document . write ( oddDivisor ( N ) ) ;

Accumulator variables: N, i
Iterator variables: i
Javascript program:
var primes = Array ( 1000006 ) . fill ( 0 ) ; function gcd ( a , b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } function preprocess ( ) { for ( i = 1 ; i <= 1000000 ; i ++ ) primes [ i ] = i ; for ( i = 2 ; i * i <= 1000000 ; i ++ ) { if ( primes [ i ] == i ) { for ( j = 2 * i ; j <= 1000000 ; j += i ) { if ( primes [ j ] == j ) primes [ j ] = i ; } } } } function Steps ( x , m ) { var steps = 0 ; var flag = false ; while ( x > 1 ) { if ( primes [ x ] > m ) { flag = true ; break ; } x /= primes [ x ] ; steps ++ ; } if ( flag ) return - 1 ; return steps ; } function minimumSteps ( x , y , m ) { preprocess ( ) ; var g = gcd ( x , y ) ; x = x / g ; y = y / g ; var x_steps = Steps ( x , m ) ; var y_steps = Steps ( y , m ) ; if ( x_steps == - 1 y_steps == - 1 ) return - 1 ; return x_steps + y_steps ; } var X = 160 ; var Y = 180 ; var M = 10 ; document . write ( minimumSteps ( X , Y , M ) ) ;

Index/key variables: i, j, x
Accumulator variables: i, j, steps, x
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function isNonDeficient ( n ) { let sum = 0 ; for ( let i = 1 ; i <= Math . floor ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( Math . floor ( n / i ) == i ) { sum = sum + i ; } else { sum = sum + i ; sum = sum + Math . floor ( n / i ) ; } } } return sum >= 2 * n ; } function LongestNonDeficientSubsequence ( arr , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isNonDeficient ( arr [ i ] ) ) { res += 1 ; } } return res ; } let arr = [ 13 , 55 , 240 , 32 , 24 , 27 , 56 , 80 , 100 , 330 , 89 ] ; let N = arr . length ; document . write ( LongestNonDeficientSubsequence ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function isPronic ( n ) { let range = Math . sqrt ( n ) ; for ( let i = 0 ; i < range + 1 ; i ++ ) { if ( i * ( i + 1 ) == n ) return true ; } return false ; } function countSub ( arr , n ) { let ans = 0 ; let ispro = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPronic ( arr [ i ] ) ) ispro += 1 ; else ispro = 0 ; ans += ispro ; } return ans ; } let arr = [ 5 , 6 , 12 , 3 , 4 ] ; let n = arr . length ; document . write ( countSub ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i, ispro
Iterator variables: i
Javascript program:
function LOG ( a , b ) { return parseInt ( Math . log ( a ) / Math . log ( b ) ) ; } function repbyNP ( arr , n ) { let x = arr [ n - 1 ] ; for ( let i = 0 ; i < n ; i ++ ) { let k = LOG ( arr [ i ] , x ) ; let temp = arr [ i ] ; if ( Math . abs ( Math . pow ( x , k ) - arr [ i ] ) < Math . abs ( Math . pow ( x , k + 1 ) - arr [ i ] ) ) arr [ i ] = Math . pow ( x , k ) ; else arr [ i ] = Math . pow ( x , k + 1 ) ; x = temp ; } } let arr = [ 2 , 4 , 6 , 3 , 11 ] ; let n = arr . length ; repbyNP ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

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

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countPairs ( arr , N ) { let odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) odd ++ ; } let ans = ( N - odd + Math . floor ( odd / 2 ) - 1 ) + Math . floor ( odd / 2 ) ; return ans ; } let arr = [ 4 , 6 , 1 , 3 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Javascript program:
function countPairs ( arr , N ) { var freq = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( freq . has ( parseInt ( Math . log2 ( arr [ i ] ) ) ) ) { freq . set ( parseInt ( Math . log2 ( arr [ i ] ) ) , freq . get ( parseInt ( Math . log2 ( arr [ i ] ) ) ) + 1 ) ; } else { freq . set ( parseInt ( Math . log2 ( arr [ i ] ) ) , 1 ) ; } } var pairs = 0 ; freq . forEach ( ( value , key ) => { pairs += value - 1 ; } ) ; return pairs ; } var arr = [ 12 , 9 , 15 , 7 ] ; var N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, pairs
Iterator variables: i
Javascript program:
function countBit ( n ) { return parseInt ( log2 ( n ) ) + 1 ; } function countSetBit ( n ) { let ans = 0 ; while ( n > 0 ) { ans += ( n & 1 ) ; n >>= 1 ; } return ans ; } function maximize ( n ) { let bits = countBit ( n ) ; let setBits = countSetBit ( n ) ; let ans = 0 ; for ( let i = 0 ; i < bits ; i ++ ) { if ( i < setBits ) ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } function minimize ( n ) { let setBits = countSetBit ( n ) ; let ans = 0 ; for ( let i = 0 ; i < setBits ; i ++ ) { ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } function maxDiff ( arr ) { let caseOne = 0 ; let SumOfOdd = 0 ; let SumOfeven = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 ) SumOfOdd += minimize ( arr [ i ] ) ; else SumOfeven += maximize ( arr [ i ] ) ; } caseOne = Math . abs ( SumOfOdd - SumOfeven ) ; let caseTwo = 0 ; SumOfOdd = 0 ; SumOfeven = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 ) SumOfOdd += maximize ( arr [ i ] ) ; else SumOfeven += minimize ( arr [ i ] ) ; } caseTwo = Math . abs ( SumOfOdd - SumOfeven ) ; return Math . max ( caseOne , caseTwo ) ; } let arr = [ 54 , 32 , 11 , 23 ] ; document . write ( maxDiff ( arr ) ) ;

Index/key variables: i
Accumulator variables: SumOfOdd, SumOfeven, ans, i
Iterator variables: i
Javascript program:
function processDiagonal ( arr ) { let ans = 0 ; let getBit = 1 ; for ( let i = 0 ; i < 32 ; i ++ ) { let S = 0 ; let NS = 0 ; for ( let j = 0 ; j < arr . length ; j ++ ) { if ( getBit & arr [ j ] ) S += 1 ; else NS += 1 ; } if ( S > NS ) ans += Math . pow ( 2 , i ) ; getBit <<= 1 ; } return ans ; } function findSum ( mat ) { let i = 0 ; let j = 0 ; let priDiag = [ ] ; while ( i < mat . length ) { priDiag . push ( mat [ i ] [ j ] ) ; i += 1 ; j += 1 ; } i = 0 ; j = mat . length - 1 ; let secDiag = [ ] ; while ( i < mat . length ) { secDiag . push ( mat [ i ] [ j ] ) ; i += 1 ; j -= 1 ; } return processDiagonal ( priDiag ) + processDiagonal ( secDiag ) ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; document . write ( findSum ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: NS, S, ans, i, j
Iterator variables: i, j
Javascript program:
function minimumDifference ( N ) { var sum1 = ( 1 << N ) , sum2 = 0 ; for ( i = 1 ; i < N / 2 ; i ++ ) sum1 += ( 1 << i ) ; for ( i = N / 2 ; i < N ; i ++ ) sum2 += ( 1 << i ) ; document . write ( sum1 - sum2 ) ; } var N = 4 ; minimumDifference ( N ) ;

Accumulator variables: i, sum1, sum2
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function printAllDivisors ( arr , N ) { let g = arr [ 0 ] ; let divisors = new Set ( ) ; for ( let i = 1 ; i < N ; i ++ ) { g = gcd ( arr [ i ] , g ) ; } for ( let i = 1 ; i * i <= g ; i ++ ) { if ( g % i == 0 ) { divisors . add ( i ) ; if ( Math . floor ( g / i ) != i ) divisors . add ( Math . floor ( g / i ) ) ; } } for ( let it of divisors . values ( ) ) document . write ( it + " " ) ; } let arr = [ 6 , 90 , 12 , 18 , 30 , 24 ] ; let n = arr . length ; printAllDivisors ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, it
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; var i ; for ( i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function getSmallestPrimefactor ( n ) { var i ; for ( i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return i ; } } var N = 100 ; var a ; a = getSmallestPrimefactor ( N ) ; if ( isPrime ( N / a ) ) document . write ( " " ) ; else document . write ( N / a ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function ispalin ( num ) { let s = num . toString ( ) ; let st = 0 , ed = s . length - 1 ; while ( st <= ed ) { if ( s [ st ] != s [ ed ] ) return false ; st ++ ; ed -- ; } return true ; } function CalculateXORandOR ( n ) { let CalculateXOR = 0 ; let CalculateOR = 0 ; let start = Math . pow ( 10 , n - 1 ) ; let end = Math . pow ( 10 , n ) - 1 ; for ( let i = start ; i <= end ; i ++ ) { if ( ispalin ( i ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } document . write ( " " + CalculateXOR ) ; document . write ( " " + CalculateOR ) ; } let n = 4 ; CalculateXORandOR ( n ) ;

Index/key variables: ed, st
Accumulator variables: ed, i, st
Iterator variables: i
Javascript program:
var pref = Array ( 100001 ) . fill ( 0 ) ; function checkPalindrome ( num ) { var str = num . toString ( ) ; var l = 0 , r = str . length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { return 0 ; } l ++ ; r -- ; } return num ; } function preCompute ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + checkPalindrome ( i ) ; } } function printSum ( L , R ) { document . write ( pref [ R ] - pref [ L - 1 ] + " " ) ; } function printSumPalindromic ( arr , Q ) { preCompute ( ) ; for ( var i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } var Q = 2 ; var arr = [ [ 10 , 13 ] , [ 12 , 21 ] ] ; printSumPalindromic ( arr , Q ) ;

Index/key variables: R, i, l, r
Accumulator variables: i, l, r
Iterator variables: i
Javascript program:
function summation ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) sum += ( i * i ) ; else sum -= ( i * i ) ; } return sum ; } let N = 2 ; document . write ( summation ( N ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countPairs ( n ) { let count = 0 ; for ( let x = 1 ; x < n ; x ++ ) { for ( let y = x + 1 ; y <= n ; y ++ ) { if ( ( y + x ) % ( y ^ x ) == 0 ) count ++ ; } } return count ; } let n = 6 ; document . write ( countPairs ( n ) ) ;

Accumulator variables: count, x, y
Iterator variables: x, y
Javascript program:
function isPower ( x , y ) { var res1 = parseInt ( Math . log ( y ) / Math . log ( x ) ) ; var res2 = Math . log ( y ) / Math . log ( x ) ; return ( res1 == res2 ) ; } function countPower ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) if ( isPower ( arr [ i ] , arr [ j ] ) || isPower ( arr [ j ] , arr [ i ] ) ) res ++ ; return res + 1 ; } var a = [ 16 , 2 , 3 , 9 ] ; var n = a . length ; document . write ( countPower ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function xor_all_elements ( n ) { switch ( n & 3 ) { case 0 : return n ; case 1 : return 1 ; case 2 : return n + 1 ; case 3 : return 0 ; } } function findArray ( xorr , n ) { let arr = [ ] ; let xor_all = xor_all_elements ( n ) ; let xor_adjacent = 0 ; for ( let i = 0 ; i < n - 1 ; i += 2 ) { xor_adjacent = xor_adjacent ^ xorr [ i ] ; } let last_element = xor_all ^ xor_adjacent ; arr . push ( last_element ) ; for ( let i = n - 2 ; i >= 0 ; i -- ) { last_element = xorr [ i ] ^ last_element ; arr . push ( last_element ) ; } return arr ; } let arr = [ ] ; let xorr = [ 7 , 5 , 3 , 7 ] ; let n = 5 ; arr = findArray ( xorr , n ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfParts ( arr , N ) { var sum_part1 = 0 , sum_part2 = 0 , sum_part3 = 0 , sum_part4 = 0 ; var totalsum = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { if ( i + j < N - 1 ) { if ( i < j && i != j && i + j > 0 ) sum_part1 += arr [ i ] [ j ] ; else if ( i != j ) sum_part2 += arr [ i ] [ j ] ; } else { if ( i > j && i + j != N - 1 ) sum_part3 += arr [ i ] [ j ] ; else { if ( i + j != N - 1 && i != j ) sum_part4 += arr [ i ] [ j ] ; } } } } totalsum = sum_part1 + sum_part2 + sum_part3 + sum_part4 ; return totalsum ; } var N = 4 ; var arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; document . write ( sumOfParts ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum_part1, sum_part2, sum_part3, sum_part4
Iterator variables: i, j
Javascript program:
function canMake ( n , ar ) { var sum = 0 , maxx = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; maxx = Math . max ( maxx , ar [ i ] ) ; } if ( n == 1 sum % 2 == 1 sum - maxx < maxx ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var n = 6 ; var arr = [ 1 , 1 , 2 , 3 , 6 , 11 ] ; canMake ( n , arr ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
var pref = Array ( 100010 ) . fill ( 0 ) ; function isPerfectSquare ( x ) { var sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ? x : 0 ; } function compute ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfectSquare ( i ) ; } } function printSum ( L , R ) { var sum = pref [ R ] - pref [ L - 1 ] ; document . write ( sum + " " ) ; } compute ( ) ; var Q = 4 ; arr = [ [ 1 , 10 ] , [ 1 , 100 ] , [ 2 , 25 ] , [ 4 , 50 ] ] ; for ( var i = 0 ; i < Q ; i ++ ) printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ;

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printMultiples ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= i ; j ++ ) { document . write ( ( i * j ) + " " ) ; } document . write ( " " ) ; } } let N = 5 ; printMultiples ( N ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function SubarraysWithSumS ( n , k , s ) { for ( let i = 0 ; i < k ; i ++ ) document . write ( s + " " ) ; for ( let i = k ; i < n ; i ++ ) document . write ( s + 1 + " " ) ; } let n = 4 , k = 2 , s = 3 ; SubarraysWithSumS ( n , k , s ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100000 ; var max_prime = Array . from ( { length : MAX + 1 } , ( _ , i ) => 0 ) ; var min_prime = Array . from ( { length : MAX + 1 } , ( _ , i ) => 0 ) ; function sieve ( n ) { for ( var i = 2 ; i <= n ; ++ i ) { if ( min_prime [ i ] > 0 ) { continue ; } min_prime [ i ] = i ; max_prime [ i ] = i ; var j = i + i ; while ( j <= n ) { if ( min_prime [ j ] == 0 ) { min_prime [ j ] = i ; } max_prime [ j ] = i ; j += i ; } } } function findSum ( arr , n ) { sieve ( MAX ) ; for ( i = 0 ; i < n ; i ++ ) { var sum = min_prime [ arr [ i ] ] + max_prime [ arr [ i ] ] ; document . write ( sum + " " ) ; } } var arr = [ 5 , 10 , 15 , 20 , 25 , 30 ] ; var n = arr . length ; findSum ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function pairCount ( n , m ) { var cnt = 0 , b , a ; for ( b = 0 ; b <= Math . sqrt ( m ) ; b ++ ) { a = m - b * b ; if ( a * a + b == n ) { cnt ++ ; } } return cnt ; } var n = 9 , m = 3 ; document . write ( pairCount ( n , m ) ) ;

Accumulator variables: b, cnt
Iterator variables: b
Javascript program:
var maxin = 100001 ; var divisors = Array ( maxin ) . fill ( 0 ) ; function Calc_Max_Div ( arr , n ) { var vis = Array ( maxin ) . fill ( 1 ) ; vis [ 0 ] = vis [ 1 ] = 0 ; var i , j ; for ( i = 1 ; i <= maxin ; i ++ ) divisors [ i ] = i ; for ( i = 4 ; i <= maxin ; i += 2 ) { vis [ i ] = 0 ; divisors [ i ] = i / 2 ; } for ( i = 3 ; i <= maxin ; i += 2 ) { if ( divisors [ i ] != i ) { divisors [ i ] = i / divisors [ i ] ; } if ( vis [ i ] == 1 ) { for ( j = i * i ; j < maxin ; j += i ) { vis [ j ] = 0 ; if ( divisors [ j ] == j ) divisors [ j ] = i ; } } } for ( i = 0 ; i < n ; i ++ ) { if ( divisors [ arr [ i ] ] == arr [ i ] ) document . write ( " " ) ; else document . write ( divisors [ arr [ i ] ] + " " ) ; } } var arr = [ 5 , 6 , 7 , 8 , 9 , 10 ] ; var n = arr . length ; Calc_Max_Div ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sumOfDigit ( n , b ) { var unitDigit , sum = 0 ; while ( n > 0 ) { unitDigit = n % b ; sum += unitDigit ; n = parseInt ( n / b ) ; } return sum ; } var n = 50 ; var b = 2 ; document . write ( sumOfDigit ( n , b ) ) ;

Accumulator variables: sum
Javascript program:
function nthDigit ( a , n , b ) { for ( var i = 1 ; i < n ; i ++ ) a = parseInt ( a / b ) ; return a % b ; } var a = 100 ; var n = 3 ; var b = 4 ; document . write ( nthDigit ( a , n , b ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function printmaxSubseq ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i + 1 ] ) document . write ( arr [ i ] + " " ) ; else document . write ( arr [ i ] + " " ) ; } } let arr = [ 9 , 8 , 11 , 13 , 10 , 15 , 14 , 16 , 20 , 5 ] ; let n = arr . length ; printmaxSubseq ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var INT_MAX = Number . MAX_VALUE ; function solve ( arr , n , k ) { var minx = INT_MAX ; var i ; for ( i = 0 ; i < n ; i ++ ) { minx = Math . min ( minx , arr [ i ] ) ; } var decrements = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] - minx ) % k != 0 ) { return - 1 ; } else { decrements += ( ( arr [ i ] - minx ) / k ) ; } } return decrements ; } var n , k ; n = 3 ; k = 3 ; var arr = [ 12 , 9 , 15 ] ; document . write ( solve ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: decrements, i
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { var C = Array ( k + 1 ) . fill ( 0 ) ; C [ 0 ] = 1 ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } function count_of_subarrays ( N ) { var count = binomialCoeff ( 2 * N - 1 , N ) ; return count ; } var N = 3 ; document . write ( count_of_subarrays ( N ) ) ;

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function distribution ( n , k , l , r , S , Sk ) { let a = new Array ( n ) ; let len = k , temp , rem , s ; let diff = S - Sk ; for ( let i = 0 ; i < len ; i ++ ) { temp = Sk / k ; rem = Sk % k ; if ( temp + rem >= l && temp + rem <= r ) { a [ i ] = temp ; } else if ( temp + rem > r ) { a [ i ] = r ; } else if ( temp + rem < r ) { document . write ( " " ) ; return ; } Sk = Sk - a [ i ] ; k = k - 1 ; } if ( Sk > 0 ) { document . write ( " " ) ; return ; } if ( len ) { k = n - len ; for ( let i = len ; i < n ; i ++ ) { temp = diff / k ; rem = diff % k ; if ( temp + rem >= l && temp + rem <= r ) { a [ i ] = temp ; } else if ( temp + rem > r ) { a [ i ] = r ; } else if ( temp + rem < r ) { document . write ( " " ) ; return ; } diff = diff - a [ i ] ; k = k - 1 ; } if ( diff ) { document . write ( " " ) ; return ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let n = 5 , k = 3 , l = 1 , r = 5 , S = 13 , Sk = 9 ; distribution ( n , k , l , r , S , Sk ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function min_index ( p , n ) { let ans = 0 ; let mini = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { if ( p [ i ] <= mini ) mini = p [ i ] ; if ( mini == p [ i ] ) ans ++ ; } return ans ; } let P = [ 4 , 2 , 5 , 1 , 3 ] ; let n = P . length ; document . write ( min_index ( P , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function equal_xor_sum ( arr , n ) { let Sum = 0 ; let Xor = 0 ; for ( let i = 0 ; i < n ; i ++ ) { Sum = Sum + arr [ i ] ; Xor = Xor ^ arr [ i ] ; } if ( Sum === Xor ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 6 , 3 , 7 , 10 ] ; let n = arr . length ; equal_xor_sum ( arr , n ) ;

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