dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function maxSum ( arr , K , start , end , max_sum ) { if ( K == 0 ) return max_sum ; let max_sum_start = max_sum + arr [ start ] ; let max_sum_end = max_sum + arr [ end ] ; let ans = Math . max ( maxSum ( arr , K - 1 , start + 1 , end , max_sum_start ) , maxSum ( arr , K - 1 , start , end - 1 , max_sum_end ) ) ; return ans ; } function maximizeSum ( arr , K , n ) { let max_sum = 0 ; let start = 0 ; let end = n - 1 ; document . write ( maxSum ( arr , K , start , end , max_sum ) ) ; } let arr = [ 8 , 4 , 4 , 8 , 12 , 3 , 2 , 9 ] ; let K = 3 ; let n = arr . length ; maximizeSum ( arr , K , n ) ;

Index/key variables: end, start
Javascript program:
function maxPointCount ( arr , k , size ) { let curr_points = 0 ; let max_points = 0 ; for ( let i = 0 ; i < K ; i ++ ) curr_points += arr [ i ] ; max_points = curr_points ; let j = size - 1 ; for ( let i = K - 1 ; i >= 0 ; i -- ) { curr_points = curr_points + arr [ j ] - arr [ i ] ; max_points = Math . max ( curr_points , max_points ) ; j -- ; } return max_points ; } let arr = [ 8 , 4 , 4 , 8 , 12 , 3 , 2 , 9 ] ; let K = 3 ; let n = arr . length ; document . write ( maxPointCount ( arr , K , n ) ) ;

Index/key variables: i, j
Accumulator variables: curr_points, i, j
Iterator variables: i
Javascript program:
function count ( N , B ) { var sum = 0 ; for ( var i = 1 ; i <= N ; i ++ ) { sum += ( B - 1 ) * Math . pow ( B , i - 1 ) ; } return sum ; } var N = 2 , B = 10 ; document . write ( count ( N , B ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function SmallestPerfectSquare ( N ) { let X = 1e9 ; let ans ; for ( let i = 1 ; i < Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { let a = i ; let b = N / i ; if ( ( b - a != 0 ) && ( ( b - a ) % 2 == 0 ) ) { X = Math . min ( X , ( b - a ) / 2 ) ; } } } if ( X != 1e9 ) ans = X * X ; else ans = - 1 ; return ans ; } let N = 3 ; document . write ( SmallestPerfectSquare ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( arr , n , circumference ) { arr . sort ( ( a , b ) => a - b ) var arr2 = Array ( 2 * n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { arr2 [ i ] = arr [ i ] ; arr2 [ i + n ] = arr [ i ] + circumference ; } var res = 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) res = Math . min ( res , arr2 [ i + ( n - 1 ) ] - arr2 [ i ] ) ; return res ; } var arr = [ 19 , 3 , 6 ] ; var n = arr . length ; var circumference = 20 ; document . write ( minCost ( arr , n , circumference ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findunique ( a , k ) { var res = 0 ; for ( var i = 0 ; i < 32 ; i ++ ) { var p = 0 ; for ( var j = 0 ; j < a . length ; j ++ ) { p += ( Math . abs ( a [ j ] ) & ( 1 << i ) ) != 0 ? 1 : 0 ; } p %= k ; res += Math . pow ( 2 , i ) * p ; } var c = 0 ; for ( var i = 0 ; i < a . length ; i ++ ) if ( a [ i ] == res ) { c = 1 ; break ; } return c == 1 ? res : - res ; } var a = [ 12 , 12 , 2 , 2 , 3 ] ; var k = 2 ; document . write ( findunique ( a , k ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, p, res
Iterator variables: i, j
Javascript program:
function calGCD ( a , b ) { if ( ! b ) { return a ; } return calGCD ( b , a % b ) ; } function MinimumGCD ( arr , n ) { var g = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) { g = calGCD ( g , arr [ i ] ) ; } return g ; } var arr = [ 2 , 4 , 6 , 8 , 3 ] ; var N = arr . length ; document . write ( MinimumGCD ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function stepRequired ( N ) { let cnt = 0 ; while ( N ) { N = N & ( N - 1 ) ; cnt ++ ; } return cnt ; } let N = 23 ; document . write ( stepRequired ( N ) ) ;

Accumulator variables: cnt
Javascript program:
function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function fibonacciSubarrays ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; ++ i ) { var sum = 0 ; for ( var j = i ; j < n ; ++ j ) { sum += arr [ j ] ; if ( isFibonacci ( sum ) ) { ++ count ; } } } document . write ( count ) ; } var arr = [ 6 , 7 , 8 , 9 ] ; var n = arr . length ; fibonacciSubarrays ( arr , n ) ;

Index/key variables: j
Accumulator variables: sum
Iterator variables: i, j
Javascript program:
function XOROfElements ( arr , n ) { var FirstHalfXOR = 0 ; var SecondHalfXOR = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i < parseInt ( n / 2 ) ) FirstHalfXOR ^= arr [ i ] ; else SecondHalfXOR ^= arr [ i ] ; } document . write ( FirstHalfXOR + " " + SecondHalfXOR + " " ) ; } var arr = [ 20 , 30 , 50 , 10 , 55 , 15 , 42 ] ; var N = arr . length ; XOROfElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: FirstHalfXOR, SecondHalfXOR, i
Iterator variables: i
Javascript program:
var N = 100005 ; var phi = Array ( N ) . fill ( 0 ) ; var pref = Array ( N ) . fill ( 0 ) ; function precompute ( ) { phi [ 1 ] = 0 ; for ( i = 2 ; i < N ; i ++ ) phi [ i ] = i ; for ( p = 2 ; p < N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( i = 2 * p ; i < N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } function prefix ( ) { for ( i = 1 ; i < N ; i ++ ) pref [ i ] = pref [ i - 1 ] + phi [ i ] ; } function find_pairs ( n ) { var total = ( n * ( n - 1 ) ) / 2 ; var ans = total - pref [ n ] ; document . write ( " " + n + " " + ans + " " ) ; } precompute ( ) ; prefix ( ) ; var q = [ 5 , 7 ] ; var n = q . length ; for ( i = 0 ; i < n ; i ++ ) { find_pairs ( q [ i ] ) ; }

Index/key variables: i, n, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function maxAlternatingSum ( arr , n ) { var max_sum = 0 ; var i = 0 ; while ( i < n ) { var current_max = arr [ i ] ; var k = i ; while ( k < n && ( ( arr [ i ] > 0 && arr [ k ] > 0 ) || ( arr [ i ] < 0 && arr [ k ] < 0 ) ) ) { current_max = Math . max ( current_max , arr [ k ] ) ; k += 1 ; } max_sum += current_max ; i = k ; } return max_sum ; } var arr = [ 1 , 2 , 3 , 4 , - 1 , - 2 ] ; var n = arr . length ; document . write ( maxAlternatingSum ( arr , n ) ) ;

Index/key variables: i, k
Accumulator variables: k, max_sum
Javascript program:
function subarrayLength ( A , R , N , M ) { for ( let i = 0 ; i < M ; ++ i ) { let l = R [ i ] [ 0 ] , r = R [ i ] [ 1 ] + 1 ; l -- ; r -- ; A [ l ] ++ ; if ( r < N ) A [ r ] -- ; } for ( let i = 1 ; i < N ; ++ i ) { A [ i ] += A [ i - 1 ] ; } let count = 0 ; let s = new Set ( ) ; for ( let i = 0 ; i < N ; ++ i ) { if ( ! s . has ( A [ i ] ) ) count ++ ; s . add ( A [ i ] ) ; } let repeat = Array . from ( { length : count + 1 } , ( _ , i ) => 0 ) ; let ans = N ; let counter = 0 , left = 0 , right = 0 ; while ( right < N ) { let cur_element = A [ right ] ; repeat [ cur_element ] += 1 ; if ( repeat [ cur_element ] == 1 ) ++ counter ; while ( counter == count ) { ans = Math . min ( ans , right - left + 1 ) ; cur_element = A [ left ] ; repeat [ cur_element ] -= 1 ; ++ left ; if ( repeat [ cur_element ] == 0 ) -- counter ; } ++ right ; } return ans ; } let N = 8 , queries = 6 ; let Q = [ [ 1 , 4 ] , [ 3 , 4 ] , [ 4 , 5 ] , [ 5 , 5 ] , [ 7 , 8 ] , [ 8 , 8 ] ] ; let A = Array . from ( { length : N } , ( _ , i ) => 0 ) ; document . write ( subarrayLength ( A , Q , N , queries ) ) ;

Index/key variables: cur_element, i, l, left, r, right
Accumulator variables: count, l, r
Iterator variables: i
Javascript program:
function ModifiedSieveOfEratosthenes ( N , Expo_Prime ) { let primes = new Array ( N ) ; primes . fill ( true ) for ( let i = 2 ; i < N ; i ++ ) { if ( primes [ i ] ) { let no = i ; while ( no <= N ) { Expo_Prime [ no ] = true ; no *= i ; } for ( let j = i * i ; j < N ; j += i ) primes [ j ] = false ; } } } function Display ( arr , Expo_Prime , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( Expo_Prime [ arr [ i ] ] ) document . write ( arr [ i ] + " " ) ; } function FindExpoPrime ( arr , n ) { let max = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( max < arr [ i ] ) max = arr [ i ] ; } let Expo_Prime = new Array ( max + 1 ) ; Expo_Prime . fill ( false ) ModifiedSieveOfEratosthenes ( max + 1 , Expo_Prime ) ; Display ( arr , Expo_Prime , n ) ; } let arr = [ 4 , 6 , 9 , 16 , 1 , 3 , 12 , 36 , 625 , 1000 ] ; let n = arr . length FindExpoPrime ( arr , n ) ;

Index/key variables: i, j, no
Accumulator variables: i, j, no
Iterator variables: i, j
Javascript program:
function nthRoot ( A , N ) { let xPre = 7 ; let eps = 1e-3 ; let delX = Number . MAX_VALUE ; let xK = 0 ; while ( delX > eps ) { xK = ( ( N - 1.0 ) * xPre + A / Math . pow ( xPre , N - 1 ) ) / N ; delX = Math . abs ( xK - xPre ) ; xPre = xK ; } return xK ; } function check ( no , k ) { let kth_root = nthRoot ( no , k ) ; let num = Math . floor ( kth_root ) ; if ( Math . abs ( num - kth_root ) < 1e-4 ) return true ; return false ; } function printExpo ( arr , n , k ) { for ( let i = 0 ; i < n ; i ++ ) { if ( check ( arr [ i ] , k ) ) document . write ( arr [ i ] + " " ) ; } } let K = 6 ; let arr = [ 46656 , 64 , 256 , 729 , 16 , 1000 ] ; let n = arr . length ; printExpo ( arr , n , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CntcontSubs ( a , n ) { let c = 0 , d = 0 , i , sum = 1 , j ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 != 0 a [ i ] % 4 == 0 ) d ++ ; sum = a [ i ] ; for ( j = i + 1 ; j < n ; j ++ ) { sum = sum * a [ j ] ; if ( sum % 2 != 0 sum % 4 == 0 ) c ++ ; } sum = 1 ; } return c + d ; } let arr = [ 5 , 4 , 2 , 9 , 8 ] ; let n = arr . length ; document . write ( CntcontSubs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: c, d, i, j
Iterator variables: i, j
Javascript program:
function CntcontSubs ( a , n ) { let prod = 1 ; let vect = [ ] ; vect . push ( [ 0 , 2 ] ) ; let two = [ ] ; let zero = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = a [ i ] % 4 ; if ( a [ i ] < 0 ) a [ i ] = a [ i ] + 4 ; if ( a [ i ] == 2 ) two . push ( i + 1 ) ; if ( a [ i ] == 0 ) zero . push ( i + 1 ) ; if ( a [ i ] == 0 a [ i ] == 2 ) vect . push ( [ i + 1 , a [ i ] ] ) ; } vect . push ( [ n + 1 , 2 ] ) ; let total = Math . floor ( ( n * ( n + 1 ) ) / 2 ) ; if ( two . length == 0 ) return total ; else { let sum = 0 ; let pos1 = - 1 , pos2 = - 1 , pos3 = - 1 ; let sz = vect . length ; for ( let i = 1 ; i + 1 < sz ; i ++ ) { if ( vect [ i ] [ 1 ] == 2 ) { sum += ( vect [ i ] [ 0 ] - vect [ i - 1 ] [ 0 ] ) * ( vect [ i + 1 ] [ 0 ] - vect [ i ] [ 0 ] ) - 1 ; } } return total - sum - two . length ; } } let a = [ 5 , 4 , 2 , 9 , 8 ] ; let n = a . length ; document . write ( CntcontSubs ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
var mod = 1000000007 ; function countSubsets ( a , n ) { var answer = 0 ; var powerOfTwo = Array ( 100005 ) . fill ( 0 ) ; powerOfTwo [ 0 ] = 1 ; for ( var i = 1 ; i < 100005 ; i ++ ) powerOfTwo [ i ] = ( powerOfTwo [ i - 1 ] * 2 ) % mod ; var frequency = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) if ( frequency . has ( a [ i ] ) ) { frequency . set ( a [ i ] , frequency . get ( a [ i ] ) + 1 ) ; } else { frequency . set ( a [ i ] , 1 ) ; } frequency . forEach ( ( value , key ) => { if ( key != 0 ) answer = ( answer % mod + powerOfTwo [ value - 1 ] ) % mod ; else answer = ( answer % mod + powerOfTwo [ value ] - 1 + mod ) % mod ; } ) ; return answer ; } var N = 6 ; var A = [ 1 , 3 , 2 , 1 , 2 , 1 ] ; document . write ( countSubsets ( A , N ) ) ;

Index/key variables: i, value
Accumulator variables: i
Iterator variables: i
Javascript program:
var pref = Array ( 100010 ) . fill ( 0 ) ; function isPerfect ( n ) { var sum = 1 ; for ( var i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return n ; return 0 ; } function precomputation ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfect ( i ) ; } } var L = 6 , R = 28 ; precomputation ( ) ; document . write ( pref [ R ] - pref [ L - 1 ] ) ;

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function convertToDecimal ( N ) { document . write ( " " + N + " " ) ; if ( N != 0 ) { let decimalNumber = 0 ; let i = 0 , remainder ; while ( N != 0 ) { remainder = N % 10 ; N = parseInt ( N / 10 , 10 ) ; decimalNumber += remainder * Math . pow ( 3 , i ) ; ++ i ; } document . write ( decimalNumber + " " ) ; } else document . write ( " " + " " ) ; } let Ternary = 10202202 ; convertToDecimal ( Ternary ) ;

Accumulator variables: decimalNumber
Javascript program:
function isPerfectSquare ( N ) { let sr = Math . sqrt ( N ) ; return ( sr - Math . floor ( sr ) ) == 0 ; } function BetrothedNumbers ( n , m ) { let Sum1 = 1 ; let Sum2 = 1 ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { Sum1 += i + ( isPerfectSquare ( n ) ? 0 : parseInt ( n / i ) ) ; } } for ( let i = 2 ; i <= Math . sqrt ( m ) ; i ++ ) { if ( m % i == 0 ) { Sum2 += i + ( isPerfectSquare ( m ) ? 0 : parseInt ( m / i ) ) ; } } if ( ( n + 1 == Sum2 ) && ( m + 1 == Sum1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let N = 9504 ; let M = 20734 ; BetrothedNumbers ( N , M ) ;

Accumulator variables: Sum1, Sum2, i
Iterator variables: i
Javascript program:
function EulerTotientFunction ( limit ) { let copy = limit ; let primes = [ ] ; for ( let i = 2 ; i * i <= limit ; i ++ ) { if ( limit % i == 0 ) { while ( limit % i == 0 ) { limit /= i ; } primes . push ( i ) ; } } if ( limit >= 2 ) { primes . push ( limit ) ; } let ans = copy ; for ( let it in primes ) { ans = ( ans / primes [ it ] ) * ( primes [ it ] - 1 ) ; } return ans ; } function CountGCD ( m , k ) { if ( m % k != 0 ) { document . write ( 0 + " " ) ; return ; } if ( m == k ) { document . write ( 2 + " " ) ; return ; } let limit = Math . floor ( m / k ) ; let ans = EulerTotientFunction ( limit ) ; document . write ( ans + " " ) ; } let M = 9 ; let K = 1 ; CountGCD ( M , K ) ;

Index/key variables: it
Accumulator variables: i, limit
Iterator variables: i, it
Javascript program:
function product ( mat , n ) { let d1 = 0 , d2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return d1 * d2 ; } let mat = [ [ 5 , 8 , 1 ] , [ 5 , 10 , 3 ] , [ - 6 , 17 , - 9 ] ] ; let n = mat . length ; document . write ( product ( mat , n ) ) ;

Index/key variables: i
Accumulator variables: d1, d2, i
Iterator variables: i
Javascript program:
function sumOfPrevK ( N , K ) { let arr = new Array ( N ) ; arr [ 0 ] = 1 ; for ( let i = 1 ; i < N ; i ++ ) { let j = i - 1 , count = 0 , sum = 0 ; while ( j >= 0 && count < K ) { sum += arr [ j ] ; j -- ; count ++ ; } arr [ i ] = sum ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let N = 10 , K = 4 ; sumOfPrevK ( N , K ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, sum
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } function findMaxGCD ( arr , n ) { let maxGCD = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let val = gcd ( arr [ i ] , arr [ i + 1 ] ) ; if ( val > maxGCD ) { maxGCD = val ; } } document . write ( maxGCD + " " ) ; } let arr = [ 3 , 18 , 9 , 9 , 5 , 15 , 8 , 7 , 6 , 9 ] ; let n = arr . length ; findMaxGCD ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSum ( arr , n , left , right ) { let k = right - left ; let d = arr [ 1 ] - arr [ 0 ] ; let ans = arr [ left - 1 ] * ( k + 1 ) ; ans = ans + ( d * ( k * ( k + 1 ) ) ) / 2 ; return ans ; } let arr = [ 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 ] ; let queries = 3 ; let q = [ [ 2 , 4 ] , [ 2 , 6 ] , [ 5 , 6 ] ] ; let n = arr . length ; for ( let i = 0 ; i < queries ; i ++ ) document . write ( findSum ( arr , n , q [ i ] [ 0 ] , q [ i ] [ 1 ] ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function subarrayPossible ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum <= 0 ) return true ; } sum = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; if ( sum <= 0 ) return true ; } return false ; } let arr = [ 10 , 5 , - 12 , 7 , - 10 , 20 , 30 , - 10 , 50 , 60 ] ; let size = arr . length ; if ( subarrayPossible ( arr , size ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function findSmallest ( N ) { if ( N == 0 ) return 2 ; if ( N == 1 ) return 1 ; var prime = N , counter = 0 ; var found = false ; while ( ! found ) { if ( isPrime ( prime ) ) found = true ; else { prime ++ ; counter ++ ; } } return counter ; } var N = 10 ; document . write ( findSmallest ( N ) ) ;

Accumulator variables: counter, prime
Iterator variables: i
Boolean variables: found
Javascript program:
var limit = 10000000 var position = Array ( limit + 1 ) . fill ( 0 ) ; function sieve ( ) { position [ 0 ] = - 1 , position [ 1 ] = - 1 ; var pos = 0 ; for ( var i = 2 ; i <= limit ; i ++ ) { if ( position [ i ] == 0 ) { position [ i ] = ++ pos ; for ( var j = i * 2 ; j <= limit ; j += i ) position [ j ] = - 1 ; } } } sieve ( ) ; var n = 11 ; document . write ( position [ n ] ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxSubArraySum ( a , size ) { var max_so_far = - 1000000000 , max_ending_here = 0 ; for ( var i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } function minPossibleSum ( a , n , x ) { var mxSum = maxSubArraySum ( a , n ) ; var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } sum = sum - mxSum + mxSum / x ; document . write ( sum ) ; } var N = 3 ; var X = 2 ; var A = [ 1 , - 2 , 3 ] ; minPossibleSum ( A , N , X ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function reverse ( num ) { var rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = parseInt ( num / 10 ) ; } return rev_num ; } function countReverse ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) if ( reverse ( arr [ i ] ) == arr [ j ] ) { res ++ ; } return res ; } var a = [ 16 , 61 , 12 , 21 , 25 ] ; var n = a . length ; document . write ( countReverse ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function reverse ( num ) { let rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = Math . floor ( num / 10 ) ; } return rev_num ; } function countReverse ( arr , n ) { let freq = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . set ( arr [ i ] , 1 ) ; } } let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq . has ( arr [ i ] ) ) { freq . set ( arr [ i ] , freq . get ( arr [ i ] ) - 1 ) ; } else { freq . set ( arr [ i ] , - 1 ) ; } if ( freq . has ( reverse ( arr [ i ] ) ) ) { res += freq . get ( reverse ( arr [ i ] ) ) ; } } return res ; } let a = [ 16 , 61 , 12 , 21 , 25 ] ; let n = a . length ; document . write ( countReverse ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
MOD = 1000000007 function rangeSum ( l , r ) { var a = 1 , b = 9 , res = 0 ; for ( var i = 1 ; i <= 10 ; i ++ ) { var L = Math . max ( l , a ) ; var R = Math . min ( r , b ) ; if ( L <= R ) { var sum = ( L + R ) * ( R - L + 1 ) / 2 ; res += Math . pow ( i , i ) * ( sum % MOD ) ; res %= MOD ; } a = a * 10 ; b = b * 10 + 9 ; } return res ; } var l = 98 , r = 102 ; document . write ( rangeSum ( l , r ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function TrialDivision ( N ) { let i = 2 ; let k = Math . ceil ( Math . sqrt ( N ) ) ; while ( i <= k ) { if ( N % i == 0 ) return 0 ; i += 1 ; } return 1 ; } let N = 49 ; let p = TrialDivision ( N ) ; if ( p ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Javascript program:
function isPossible ( A , n , k ) { var countOfTwo = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( A [ i ] % 2 == 0 ) { countOfTwo ++ ; } } if ( k == 0 && countOfTwo == n ) document . write ( " " ) ; else if ( countOfTwo >= k ) { document . write ( " " ) ; } else document . write ( " " ) ; } var arr = [ 1 , 2 , 4 , 5 ] ; var K = 2 ; var N = arr . length ; isPossible ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: countOfTwo, i
Iterator variables: i
Javascript program:
function pairs ( n ) { let c = new Array ( 10 ) ; for ( var i = 0 ; i < c . length ; i ++ ) { c [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < c . length ; i ++ ) { for ( var j = 0 ; j < c . length ; j ++ ) { c [ i ] [ j ] = 0 ; } } let tmp = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i >= tmp * 10 ) tmp *= 10 ; c [ Math . floor ( i / tmp ) ] [ i % 10 ] ++ ; } let ans = 0 ; for ( let i = 1 ; i < 10 ; i ++ ) for ( let j = 1 ; j < 10 ; j ++ ) ans += c [ i ] [ j ] * c [ j ] [ i ] ; return ans ; } let n = 25 ; document . write ( pairs ( n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j, tmp
Iterator variables: i, j
Javascript program:
function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function gcdFibonacciFreq ( arr , n ) { let hash = new Set ( ) ; createHash ( hash , arr . sort ( ( a , b ) => b - a ) [ 0 ] ) ; let i , j ; let m = new Map ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) } } let gcd = 0 ; for ( let it of m ) { if ( hash . has ( it [ 1 ] ) ) { gcd = __gcd ( gcd , it [ 0 ] ) ; } } return gcd ; } function __gcd ( a , b ) { return ( b == 0 ? a : __gcd ( b , a % b ) ) ; } let arr = [ 5 , 3 , 6 , 5 , 6 , 6 , 5 , 5 ] ; let n = arr . length ; document . write ( gcdFibonacciFreq ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, it
Javascript program:
function printSeries ( N ) { let ith_term = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { ith_term = i % 2 == 0 ? 2 * i * i + 1 : 2 * i * i - 1 ; document . write ( ith_term + " " ) ; } } let N = 7 ; printSeries ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findNthTerm ( N ) { let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { ans = ans + 6 ; } else { ans = ans + 2 ; } } document . write ( ans + " " ) ; } let N = 3 ; findNthTerm ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
size = 10001 prime = Array ( size ) . fill ( 0 ) ; freq = Array ( size ) . fill ( 0 ) ; function sieve ( a , b ) { prime [ 1 ] = 1 ; for ( var i = 2 ; i * i < size ; i ++ ) { if ( prime [ i ] == 0 ) { for ( var j = i * 2 ; j < size ; j += i ) prime [ j ] = 1 ; } } for ( var p = 1 ; p < size ; p ++ ) { for ( var q = 1 ; q < size ; q ++ ) { if ( prime [ p ] == 0 && prime [ q ] == 0 && a * p + b * q < size ) { freq [ a * p + b * q ] ++ ; } } } } var queries = 2 , a = 1 , b = 2 ; sieve ( a , b ) ; var arr = [ 15 , 25 ] ; for ( var i = 0 ; i < queries ; i ++ ) { document . write ( freq [ arr [ i ] ] + " " ) ; }

Index/key variables: i, j, p, q
Accumulator variables: i, j, p, q
Iterator variables: i, j, p, q
Javascript program:
function printSeriesSum ( N ) { let sum = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { if ( i & 1 ) { sum += i / ( i + 1 ) ; } else { sum -= i / ( i + 1 ) ; } } document . write ( sum . toFixed ( 6 ) ) ; } let N = 10 ; printSeriesSum ( N ) ;

Accumulator variables: i, sum
Iterator variables: i