dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function largestElement ( head_ref ) { var max = Number . MIN_VALUE ; var head = head_ref ; while ( head != null ) { if ( max < head . data ) max = head . data ; head = head . next ; } return max ; } function createHash ( hash , maxElement ) { var prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { var temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function sumAndProduct ( head_ref ) { var maxEle = largestElement ( head_ref ) ; var hash = new Set ( ) ; createHash ( hash , maxEle ) ; var prod = 1 ; var sum = 0 ; var ptr = head_ref ; while ( ptr != null ) { if ( hash . has ( ptr . data ) ) { prod *= ptr . data ; sum += ptr . data ; } ptr = ptr . next ; } document . write ( " " + sum + " " ) ; document . write ( " " + prod ) ; } var head = null ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 8 ) ; head = push ( head , 16 ) ; head = push ( head , 15 ) ; sumAndProduct ( head ) ;

Accumulator variables: prod, sum
Class/struct names: Node
Javascript program:
function val ( c ) { if ( c >= ' ' && c <= ' ' ) return c . charCodeAt ( ) - ' ' . charCodeAt ( ) ; else return c . charCodeAt ( ) - ' ' . charCodeAt ( ) + 10 ; } function toDeci ( str , base ) { let len = str . length ; let power = 1 ; let num = 0 ; let i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str [ i ] ) >= base ) { document . write ( " " ) ; return - 1 ; } num += val ( str [ i ] ) * power ; power = power * base ; } return num ; } function isEven ( num , N ) { let deci = toDeci ( num , N ) ; return ( deci % 2 == 0 ) ; } let num = " " ; let N = 16 ; if ( isEven ( num , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, num
Iterator variables: i
Javascript program:
fact = Array ( 21 ) . fill ( 0 ) ; function preCompute ( ) { fact [ 0 ] = 1 ; for ( var i = 1 ; i < 18 ; i ++ ) fact [ i ] = ( fact [ i - 1 ] * i ) ; } function nextFactorial ( N ) { for ( var i = 0 ; i < 21 ; i ++ ) { if ( N < fact [ i ] ) { document . write ( fact [ i ] ) ; break ; } } } preCompute ( ) ; var N = 120 ; nextFactorial ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findDistinctOddSum ( n , k ) { if ( ( k * k ) <= n && ( n + k ) % 2 == 0 ) { var val = 1 ; var sum = 0 ; for ( var i = 1 ; i < k ; i ++ ) { document . write ( val + " " ) ; sum += val ; val += 2 ; } document . write ( n - sum ) ; } else document . write ( " " ) ; } var n = 100 ; var k = 4 ; findDistinctOddSum ( n , k ) ;

Accumulator variables: i, sum, val
Iterator variables: i
Javascript program:
function checkArray ( a , b , n ) { var operations = 0 ; var i = 0 ; while ( i < n ) { if ( a [ i ] - b [ i ] == 0 ) { i ++ ; continue ; } var diff = a [ i ] - b [ i ] ; i ++ ; while ( i < n && a [ i ] - b [ i ] == diff ) { i ++ ; } operations ++ ; } document . write ( operations ) ; } var a = [ 3 , 7 , 1 , 4 , 1 , 2 ] ; var b = [ 3 , 7 , 3 , 6 , 3 , 2 ] ; var size = a . length ; checkArray ( a , b , size ) ;

Index/key variables: i
Accumulator variables: i, operations
Javascript program:
function insertPF ( primeFact , fact ) { if ( primeFact . has ( fact ) ) { primeFact . set ( fact , primeFact . get ( fact ) + 1 ) ; } else { primeFact . set ( fact , 1 ) ; } return primeFact ; } function primeFactors ( n ) { var primeFact = new Map ( ) ; while ( n % 2 == 0 ) { primeFact = insertPF ( primeFact , 2 ) ; n = parseInt ( n / 2 ) ; } for ( var i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { primeFact = insertPF ( primeFact , i ) ; n = parseInt ( n / i ) ; } } if ( n > 2 ) primeFact = insertPF ( primeFact , n ) ; return primeFact ; } function perfectCube ( n ) { var primeFact = new Map ( ) ; primeFact = primeFactors ( n ) ; primeFact . forEach ( ( value , key ) => { if ( value % 3 != 0 ) return " " ; } ) ; return " " ; } var N = 216 ; document . write ( perfectCube ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { return ( n == 1 n == 0 ) ? 1 : n * factorial ( n - 1 ) ; } function ways ( n ) { if ( n < 3 ) { return 0 ; } let c2 = 0 ; let c1 = n - 3 ; let l = c1 + 1 ; let s = 0 ; let exp_c2 = Math . floor ( c1 / 2 ) ; while ( exp_c2 >= c2 ) { let f1 = factorial ( l ) ; let f2 = factorial ( c1 ) ; let f3 = factorial ( c2 ) ; let f4 = ( f2 * f3 ) ; s += Math . floor ( f1 / f4 ) ; c2 += 1 ; c1 -= 2 ; l -= 1 ; } return s ; } let n = 7 ; let ans = ways ( n ) ; document . write ( ans ) ;

Accumulator variables: c1, c2, l, s
Javascript program:
var m = { } ; function precompute ( ) { var fact = 1 ; for ( var i = 1 ; i <= 18 ; i ++ ) { fact = fact * i ; m [ fact ] = i ; } } precompute ( ) ; var K = 120 ; document . write ( m [ K ] + " " ) ; K = 6 ; document . write ( m [ K ] ) ;

Index/key variables: K, fact
Accumulator variables: i
Iterator variables: i
Javascript program:
function calNum ( year ) { return parseInt ( year / 4 , 10 ) - parseInt ( year / 100 , 10 ) + parseInt ( year / 400 , 10 ) ; } function leapNum ( l , r ) { l -- ; let num1 = calNum ( r ) ; let num2 = calNum ( l ) ; document . write ( ( num1 - num2 ) + " " ) ; } let l1 = 1 , r1 = 400 ; leapNum ( l1 , r1 ) ; let l2 = 400 , r2 = 2000 ; leapNum ( l2 , r2 ) ;

Accumulator variables: l
Javascript program:
class Cantor { constructor ( ) { this . start = 0 ; this . end = 0 ; this . next = null ; } } ; var cantor = null ; function startList ( head , start_num , end_num ) { if ( head == null ) { head = new Cantor ( ) ; head . start = start_num ; head . end = end_num ; head . next = null ; } return head ; } function propagate ( head ) { var temp = head ; if ( temp != null ) { var newNode = new Cantor ( ) ; var diff = ( ( ( temp . end ) - ( temp . start ) ) / 3 ) ; newNode . end = temp . end ; temp . end = ( ( temp . start ) + diff ) ; newNode . start = ( newNode . end ) - diff ; newNode . next = temp . next ; temp . next = newNode ; propagate ( temp . next . next ) ; } return head ; } function print ( temp ) { while ( temp != null ) { document . write ( " " + temp . start . toFixed ( 6 ) + " " + temp . end . toFixed ( 6 ) + " " ) ; temp = temp . next ; } document . write ( " " ) ; } function buildCantorSet ( A , B , L ) { var head = null ; head = startList ( head , A , B ) ; for ( var i = 0 ; i < L ; i ++ ) { document . write ( " " + i + " " ) ; print ( head ) ; propagate ( head ) ; } document . write ( " " + L + " " ) ; print ( head ) ; } var A = 0 ; var B = 9 ; var L = 2 ; buildCantorSet ( A , B , L ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: Cantor
Javascript program:
function countNumber ( N , S ) { let countElements = 0 ; let currSum = 0 ; while ( currSum <= S ) { currSum += N ; N -- ; countElements ++ ; } return countElements ; } let N , S ; N = 5 ; S = 11 ; let count = countNumber ( N , S ) ; document . write ( count + " " ) ;

Accumulator variables: N, countElements, currSum
Javascript program:
let INT_MAX = Number . MAX_VALUE ; function countDistinct ( n ) { let arr = new Array ( 10 ) ; arr . fill ( 0 ) ; let count = 0 ; while ( n != 0 ) { let r = n % 10 ; arr [ r ] = 1 ; n = parseInt ( n / 10 , 10 ) ; } for ( let i = 0 ; i < 10 ; i ++ ) { if ( arr [ i ] != 0 ) count ++ ; } return count ; } function countDigit ( n ) { let c = 0 ; while ( n != 0 ) { let r = n % 10 ; c ++ ; n = parseInt ( n / 10 , 10 ) ; } return c ; } function nextNumberDistinctDigit ( n ) { while ( n < INT_MAX ) { let distinct_digits = countDistinct ( n + 1 ) ; let total_digits = countDigit ( n + 1 ) ; if ( distinct_digits == total_digits ) { return n + 1 ; } else n ++ ; } return - 1 ; } let n = 2019 ; document . write ( nextNumberDistinctDigit ( n ) ) ;

Index/key variables: i, r
Accumulator variables: c, count, i, n
Iterator variables: i
Javascript program:
function findNumberOfEvenCells ( n , q , size ) { let row = new Array ( n ) ; row . fill ( 0 ) ; let col = new Array ( n ) ; col . fill ( 0 ) ; for ( let i = 0 ; i < size ; i ++ ) { let x = q [ i ] [ 0 ] ; let y = q [ i ] [ 1 ] ; row [ x - 1 ] ++ ; col [ y - 1 ] ++ ; } let r1 = 0 , r2 = 0 ; let c1 = 0 , c2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( row [ i ] % 2 == 0 ) { r1 ++ ; } if ( row [ i ] % 2 == 1 ) { r2 ++ ; } if ( col [ i ] % 2 == 0 ) { c1 ++ ; } if ( col [ i ] % 2 == 1 ) { c2 ++ ; } } let count = r1 * c1 + r2 * c2 ; return count ; } let n = 2 ; let q = [ [ 1 , 1 ] , [ 1 , 2 ] , [ 2 , 1 ] ] ; let size = q . length ; document . write ( findNumberOfEvenCells ( n , q , size ) ) ;

Index/key variables: i
Accumulator variables: c1, c2, i, r1, r2
Iterator variables: i
Javascript program:
function FermatFactors ( n ) { if ( n <= 0 ) { document . write ( " " + n + " " ) ; return ; } if ( ( n & 1 ) == 0 ) { document . write ( " " + ( n / 2.0 ) + " " + ( 2 ) + " " ) ; return ; } let a = Math . ceil ( Math . sqrt ( n ) ) ; if ( a * a == n ) { document . write ( " " + a + " " + a + " " ) ; return ; } let b ; while ( true ) { let b1 = a * a - n ; b = parseInt ( Math . sqrt ( b1 ) , 10 ) ; if ( b * b == b1 ) break ; else a += 1 ; } document . write ( " " + ( a - b ) + " " + ( a + b ) + " " ) ; return ; } FermatFactors ( 6557 ) ;

Accumulator variables: a
Javascript program:
function findNums ( arr , n ) { var S = 0 , X = 0 ; for ( i = 0 ; i < n ; i ++ ) { S += arr [ i ] ; X ^= arr [ i ] ; } document . write ( X + " " + ( X + S ) ) ; } var arr = [ 1 , 7 ] ; var n = arr . length ; findNums ( arr , n ) ;

Index/key variables: i
Accumulator variables: S, X, i
Iterator variables: i
Javascript program:
function findLargest ( arr , n ) { var gcd = 0 ; for ( i = 0 ; i < n ; i ++ ) gcd = __gcd ( arr [ i ] , gcd ) ; return gcd ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var arr = [ 3 , 6 , 9 ] ; var n = arr . length ; document . write ( findLargest ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function digitSum ( n ) { let sum = 0 ; while ( n > 0 ) { sum += ( n % 10 ) ; n = parseInt ( n / 10 , 10 ) ; } return sum ; } function isPalindrome ( n ) { let divisor = 1 ; while ( parseInt ( n / divisor , 10 ) >= 10 ) divisor *= 10 ; while ( n != 0 ) { let leading = parseInt ( n / divisor , 10 ) ; let trailing = n % 10 ; if ( leading != trailing ) return false ; n = parseInt ( ( n % divisor ) / 10 , 10 ) ; divisor = parseInt ( divisor / 100 , 10 ) ; } return true ; } function isDigitSumPalindrome ( n ) { let sum = digitSum ( n ) ; if ( isPalindrome ( sum ) ) return true ; return false ; } let n = 56 ; if ( isDigitSumPalindrome ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: divisor, sum
Javascript program:
let N = 20 ; let mod = 1000000007 ; let factorial = new Array ( N ) ; factorial . fill ( 0 ) ; let modinverse = new Array ( N ) ; modinverse . fill ( 0 ) ; function power ( a , m1 ) { if ( m1 == 0 ) return 1 ; else if ( m1 == 1 ) return a ; else if ( m1 == 2 ) return ( a * a ) % mod ; else if ( ( m1 & 1 ) != 0 ) return ( a * power ( power ( a , parseInt ( m1 / 2 , 10 ) ) , 2 ) ) % mod ; else return power ( power ( a , parseInt ( m1 / 2 , 10 ) ) , 2 ) % mod ; } function factorialfun ( ) { factorial [ 0 ] = 1 ; for ( let i = 1 ; i < N ; i ++ ) factorial [ i ] = ( factorial [ i - 1 ] * i ) % mod ; } function modinversefun ( ) { modinverse [ N - 1 ] = power ( factorial [ N - 1 ] , mod - 2 ) % mod ; for ( let i = N - 2 ; i >= 0 ; i -- ) modinverse [ i ] = ( modinverse [ i + 1 ] * ( i + 1 ) ) % mod ; } function binomial ( n , r ) { if ( r > n ) return 0 ; let a = ( factorial [ n ] * modinverse [ n - r ] ) % mod ; a = ( a * modinverse [ r ] ) % mod ; return a ; } function arrange ( n , m , k ) { factorialfun ( ) ; modinversefun ( ) ; let ans = 0 ; for ( let i = 1 ; i < n ; i ++ ) ans += ( i * ( n - i ) * m * m ) % mod ; ans = 8 ; for ( let i = 1 ; i < m ; i ++ ) ans += ( i * ( m - i ) * n * n ) % mod ; ans = ( ans * binomial ( n * m - 2 , k - 2 ) * 0 ) % mod + 8 ; return ans ; } let n = 2 , m = 2 , k = 2 ; document . write ( arrange ( n , m , k ) ) ;

Index/key variables: i, n, r
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findNthDigit ( p , q , N ) { var res ; while ( N > 0 ) { N -- ; p *= 10 ; res = parseInt ( p / q ) ; p %= q ; } return res ; } var p = 1 , q = 2 , N = 1 ; document . write ( findNthDigit ( p , q , N ) ) ;

Accumulator variables: N, p
Javascript program:
function sumArr ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } function sumModArr ( arr , n ) { var subSum = arr [ n - 1 ] ; for ( var i = n - 2 ; i >= 0 ; i -- ) { var curr = arr [ i ] ; arr [ i ] -= subSum ; subSum += curr ; } return sumArr ( arr , n ) ; } var arr = [ 40 , 25 , 12 , 10 ] ; var n = arr . length ; document . write ( sumModArr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, subSum, sum
Iterator variables: i
Javascript program:
let NumUnsignBits = 64 ; function findNum ( x ) { for ( let i = 0 ; i < NumUnsignBits - 1 ; i ++ ) { if ( ( ( x >> i ) & 1 ) != ( ( x >> ( i + 1 ) ) & 1 ) ) { x ^= ( 1 << i ) | ( 1 << ( i + 1 ) ) ; return x ; } } return Number . MIN_VALUE ; } let n = 92 ; document . write ( findNum ( n ) ) ;

Accumulator variables: i, x
Iterator variables: i
Javascript program:
function reverse ( num ) { let rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num = parseInt ( num / 10 , 10 ) ; } return rev ; } function isPalindrome ( num ) { if ( num == reverse ( num ) ) return true ; return false ; } function printPalindromes ( d ) { if ( d <= 0 ) return ; let smallest = Math . pow ( 10 , d - 1 ) ; let largest = Math . pow ( 10 , d ) - 1 ; for ( let i = smallest ; i <= largest ; i ++ ) { if ( isPalindrome ( i ) ) document . write ( i + " " ) ; } } let d = 2 ; printPalindromes ( d ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function min_moves ( n ) { let ans = Number . MAX_VALUE ; for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { ans = Math . min ( ans , i + parseInt ( n / i , 10 ) - 2 ) ; } } return ans ; } let n = 10 ; document . write ( min_moves ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let MOD = 2019 ; function min_modulo ( l , r ) { if ( r - l >= MOD ) return 0 ; else { let ans = MOD - 1 ; for ( let i = l ; i <= r ; i ++ ) { for ( let j = i + 1 ; j <= r ; j ++ ) { ans = Math . min ( ans , ( i * j ) % MOD ) ; } } return ans ; } } let l = 2020 , r = 2040 ; document . write ( min_modulo ( l , r ) ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countPairs ( arr , n ) { var map = { } ; for ( var i = 0 ; i < n ; i ++ ) map [ arr [ i ] - i ] = 0 ; for ( var i = 0 ; i < n ; i ++ ) map [ arr [ i ] - i ] ++ ; var res = 0 ; for ( const [ key , value ] of Object . entries ( map ) ) { var cnt = value ; res += ( cnt * ( cnt - 1 ) ) / 2 ; } return res ; } var arr = [ 1 , 5 , 6 , 7 , 9 ] ; var n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function minInt ( str ) { for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . charCodeAt ( ) >= ( ' ' ) . charCodeAt ( ) ) { str [ i ] = String . fromCharCode ( ( ( ' ' ) . charCodeAt ( ) - ( str [ i ] ) . charCodeAt ( ) ) + ( ' ' ) . charCodeAt ( ) ) ; } } if ( str [ 0 ] == ' ' ) str [ 0 ] = ' ' ; let s = str . join ( " " ) ; return s ; } let str = " " ; document . write ( minInt ( str . split ( ' ' ) ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minOperations ( n ) { var count = 0 ; var d = 0 ; if ( n == 1 ) return 0 ; while ( n > 9 ) { d = Math . max ( n % 10 , d ) ; n /= 10 ; count += 10 ; } d = Math . max ( d , n - 1 ) ; count += Math . abs ( d ) ; return count - 1 ; } var n = 240 ; document . write ( minOperations ( n ) ) ;

Accumulator variables: count, n
Javascript program:
function findMaximumNum ( str , n , k ) { for ( var i = 0 ; i < n ; i ++ ) { if ( k < 1 ) break ; if ( str [ i ] !== " " ) { str [ i ] = " " ; k -- ; } } return str . join ( " " ) ; } var str = " " ; var n = str . length ; var k = 3 ; document . write ( findMaximumNum ( str . split ( " " ) , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k
Iterator variables: i
Javascript program:
function prime ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function thirdNumber ( a , b ) { let sum = 0 , temp = 0 ; sum = a + b ; temp = 1 ; if ( ( sum & 1 ) != 0 ) { temp = 2 ; } while ( ! prime ( sum + temp ) ) { temp += 2 ; } document . write ( temp ) ; } let a = 3 , b = 5 ; thirdNumber ( a , b ) ;

Accumulator variables: i, temp
Iterator variables: i
Javascript program:
function nCr ( n , r ) { let ans = 1 ; for ( let i = 1 ; i <= r ; i += 1 ) { ans *= ( n - r + i ) ; ans /= i ; } return ans ; } function total_ways ( N , X ) { return ( nCr ( N - 1 , X - 1 ) + nCr ( N - 1 , X ) ) ; } let N = 5 , X = 3 ; document . write ( total_ways ( N , X ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function printNumber ( holes ) { if ( holes == 0 ) document . write ( " " ) ; else if ( holes == 1 ) document . write ( " " ) ; else { let rem = 0 , quo = 0 ; rem = holes % 2 ; quo = parseInt ( holes / 2 , 10 ) ; if ( rem == 1 ) document . write ( " " ) ; for ( let i = 0 ; i < quo ; i ++ ) document . write ( " " ) ; } } let holes = 3 ; printNumber ( holes ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( arr , n ) { var count_even = 0 ; var count_odd = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) count_even ++ ; else count_odd ++ ; } return Math . min ( count_even , count_odd ) ; } var arr = [ 2 , 4 , 3 , 1 , 5 ] ; var n = arr . length ; document . write ( minCost ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count_even, count_odd, i
Iterator variables: i
Javascript program:
function negProdSubArr ( arr , n ) { let positive = 1 , negative = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) arr [ i ] = 1 ; else arr [ i ] = - 1 ; if ( i > 0 ) arr [ i ] *= arr [ i - 1 ] ; if ( arr [ i ] == 1 ) positive ++ ; else negative ++ ; } return ( positive * negative ) ; } function posProdSubArr ( arr , n ) { let total = parseInt ( ( n * ( n + 1 ) ) / 2 ) ; let cntNeg = negProdSubArr ( arr , n ) ; return ( total - cntNeg ) ; } let arr = [ 5 , - 4 , - 3 , 2 , - 5 ] ; let n = arr . length ; document . write ( posProdSubArr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, negative, positive
Iterator variables: i
Javascript program:
let MAX = 10000 ; let prime = new Array ( MAX + 1 ) ; function SieveOfEratosthenes ( ) { let i ; for ( i = 0 ; i < MAX + 1 ; i ++ ) { prime [ i ] = true ; } prime [ 1 ] = false ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function xorFirstNPrime ( n ) { let count = 0 , num = 1 ; let xorVal = 0 ; while ( count < n ) { if ( prime [ num ] ) { xorVal ^= num ; count ++ ; } num ++ ; } return xorVal ; } SieveOfEratosthenes ( ) ; let n = 4 ; document . write ( xorFirstNPrime ( n ) ) ;

Index/key variables: i, num, p
Accumulator variables: count, i, num, p, xorVal
Iterator variables: i, p
Javascript program:
let mod = 1000000007 ; let inv2 = 500000004 ; function modulo ( num ) { let res = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) res = ( res * 10 + num [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) % mod ; return res ; } function findSum ( L , R ) { let a , b , l , r , ret ; a = modulo ( L ) ; b = modulo ( R ) ; l = ( ( a * ( a - 1 ) ) % mod * inv2 ) % mod ; r = ( ( b * ( b + 1 ) ) % mod * inv2 ) % mod ; ret = ( r % mod - l % mod ) ; if ( ret < 0 ) ret = ret + mod ; else ret = ret % mod - 6 ; return ret ; } let L = " " ; let R = " " ; document . write ( findSum ( L , R ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubArraySum ( a , n , k , i ) { let max_so_far = Number . MIN_VALUE , max_ending_here = 0 ; while ( i < n ) { 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 ; i += k ; } return max_so_far ; } function find ( arr , n , k ) { let maxSum = 0 ; for ( let i = 0 ; i <= Math . min ( n , k ) ; i ++ ) { let sum = 0 ; maxSum = Math . max ( maxSum , maxSubArraySum ( arr , n , k , i ) ) ; } return maxSum ; } let arr = [ 2 , - 3 , - 1 , - 1 , 2 ] ; let n = arr . length ; let k = 2 ; document . write ( find ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const MAX = 1000000 ; let prime = new Array ( MAX + 1 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { prime [ 1 ] = false ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function solve ( n ) { let count = 0 ; for ( let i = 3 ; count < n ; i ++ ) { if ( prime [ i ] ) { document . write ( i + " " ) ; count ++ ; } } } SieveOfEratosthenes ( ) ; let n = 6 ; solve ( n ) ;

Index/key variables: i, p
Accumulator variables: count, i, p
Iterator variables: i, p
Javascript program:
function solve ( n ) { let n_2 = parseInt ( n / 2 , 10 ) ; let den ; den = " " ; while ( n_2 -- > 0 ) den += ' ' ; document . write ( 1 + " " + den + " " ) ; } let N = 5 ; solve ( N ) ;

Accumulator variables: den, n_2
Javascript program:
MOD = 1000000007 ; function countWays ( n ) { var ans = 1 ; for ( i = 0 ; i < n ; i ++ ) { ans *= 2 ; ans %= MOD ; } return ( ( ans - 1 + MOD ) % MOD ) ; } var n = 3 ; document . write ( countWays ( n ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findMin ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; arr . sort ( ) ; let min = arr [ 0 ] ; let max = 0 ; for ( let i = n - 1 ; i >= 1 ; i -- ) { let num = arr [ i ] ; let total = num + min ; let j ; for ( j = 2 ; j <= num ; j ++ ) { if ( num % j == 0 ) { let d = j ; let now = parseInt ( num / d ) + ( min * d ) ; let reduce = total - now ; if ( reduce > max ) max = reduce ; } } } document . write ( sum - max ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; findMin ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function convert_To_Len_th_base ( n , arr , len , L ) { for ( i = 0 ; i < L ; i ++ ) { document . write ( parseInt ( arr [ n % len ] ) ) ; n = parseInt ( n / len ) ; } document . write ( " " ) ; } function print ( arr , len , L ) { for ( var i = 0 ; i < parseInt ( Math . pow ( len , L ) ) ; i ++ ) { convert_To_Len_th_base ( i , arr , len , L ) ; } } var arr = [ 1 , 2 , 3 ] ; var len = arr . length ; var L = 2 ; print ( arr , len , L ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function totalways ( arr , n ) { var cnt = { } ; for ( var i = 0 ; i < n ; i ++ ) { if ( cnt . hasOwnProperty ( arr [ i ] ) ) { cnt [ arr [ i ] ] = cnt [ arr [ i ] ] + 1 ; } else { cnt [ arr [ i ] ] = 1 ; } } if ( n % 2 === 1 ) { var start = 0 , endd = n - 1 ; for ( var i = start ; i <= endd ; i = i + 2 ) { if ( i === 0 ) { if ( cnt [ i ] !== 1 ) { return 0 ; } } else { if ( cnt [ i ] !== 2 ) { return 0 ; } } } var ways = 1 ; start = 2 ; endd = n - 1 ; for ( var i = start ; i <= endd ; i = i + 2 ) { ways = ways * 2 ; } return ways ; } else if ( n % 2 === 0 ) { var start = 1 , endd = n - 1 ; for ( var i = 1 ; i <= endd ; i = i + 2 ) { if ( cnt [ i ] !== 2 ) return 0 ; } var ways = 1 ; for ( var i = start ; i <= endd ; i = i + 2 ) { ways = ways * 2 ; } return ways ; } return - 2147483648 ; } var N = 5 ; var arr = [ 2 , 4 , 4 , 0 , 2 ] ; document . write ( totalways ( arr , N ) ) ;

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