dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function primeFactor ( N ) { let v = [ ] ; let count = 0 ; while ( ! ( N % 2 ) ) { N >>= 1 ; count ++ ; } if ( count ) v . push ( [ 2 , count ] ) ; for ( let i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = Math . floor ( N / i ) ; } if ( count ) { v . push ( [ i , count ] ) ; } } if ( N > 2 ) v . push ( [ N , 1 ] ) ; return v ; } function printAnswer ( n ) { let v = primeFactor ( n ) ; let maxi_size = 0 , prime_factor = 0 ; for ( let i = 0 ; i < v . length ; i ++ ) { if ( maxi_size < v [ i ] [ 1 ] ) { maxi_size = v [ i ] [ 1 ] ; prime_factor = v [ i ] [ 0 ] ; } } if ( maxi_size < 2 ) { document . write ( 1 + ' ' + n ) ; } else { let product = 1 ; document . write ( maxi_size + " " ) ; for ( let i = 0 ; i < maxi_size - 1 ; i ++ ) { document . write ( prime_factor + " " ) ; product *= prime_factor ; } document . write ( Math . floor ( ( n / product ) ) ) ; } } let N = 360 ; printAnswer ( N ) ;

Index/key variables: i
Accumulator variables: count, i, product
Iterator variables: i
Javascript program:
function ABS ( x ) { return Math . max ( x , - x ) ; } function findFraction ( x , y , n ) { let A = - 1 , B = - 1 ; for ( let i = 1 ; i <= n ; i ++ ) { let d = Math . floor ( ( i * x ) / y ) ; if ( d >= 0 && ( A == - 1 || ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) A = d ; B = i ; d ++ ; if ( d >= 0 && ( A == - 1 || ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) A = d ; B = i ; } A -- ; B -- ; document . write ( A + " " + B ) ; } let x = 3 ; let y = 7 ; let n = 6 ; findFraction ( x , y , n ) ;

Accumulator variables: A, B, d, i
Iterator variables: i
Javascript program:
function BaseConversion ( N ) { let s = " " ; while ( N != 0 ) { if ( N % 2 == 0 ) { s = " " + s ; } else { s = " " + s ; N -- ; } N /= - 2 ; } if ( s == " " ) { s = " " ; } return s ; } let N = - 9 ; document . write ( BaseConversion ( N ) ) ;

Accumulator variables: N
Javascript program:
function finalInstances ( instances , arr ) { let i = 0 ; while ( i < arr . length ) { if ( arr [ i ] < 25 && instances > 1 ) { instances = Math . ceil ( instances / 2 ) ; i = i + 10 ; } else if ( arr [ i ] > 60 && instances <= Math . pow ( 10 , 8 ) ) { instances = instances * 2 ; i = i + 10 ; } i = i + 1 ; } document . write ( instances ) ; } let instances = 2 ; let arr = [ 25 , 23 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 76 , 80 ] ; finalInstances ( instances , arr ) ;

Index/key variables: i
Javascript program:
function isMakeZero ( arr , N , K ) { let MP = new Map ( ) ; let V = [ ] ; let X = 1 ; let i ; while ( X > 0 && X < Number . MAX_VALUE ) { V . push ( X ) ; X *= K ; } for ( i = 0 ; i < N ; i ++ ) { for ( let j = V . length - 1 ; j >= 0 ; j -- ) { if ( MP . has ( V [ j ] ) == false && V [ j ] <= arr [ i ] ) { arr [ i ] -= V [ j ] ; MP . set ( V [ j ] , 1 ) ; } } if ( arr [ i ] != 0 ) break ; } if ( i < N ) return " " ; else return " " ; } let arr = [ 8 , 0 , 3 , 4 , 80 ] ; let N = arr . length ; let K = 2 ; document . write ( isMakeZero ( arr , N , K ) ) ;

Index/key variables: i, j
Accumulator variables: X, i, j
Iterator variables: i, j
Javascript program:
function perfectSquare ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let p = Math . sqrt ( arr [ i ] ) ; if ( p * p != arr [ i ] ) { return " " ; } } return " " ; } let arr = [ 1 , 4 , 100 ] ; let N = arr . length ; document . write ( perfectSquare ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countKAverageSubarrays ( arr , n , k ) { let res = 0 ; for ( let L = 0 ; L < n ; L ++ ) { let sum = 0 ; for ( let R = L ; R < n ; R ++ ) { sum += arr [ R ] ; let len = R - L + 1 ; if ( sum % len == 0 ) { let avg = sum / len ; if ( avg == k ) res ++ ; } } } return res ; } let K = 6 ; let arr = [ 12 , 5 , 3 , 10 , 4 , 8 , 10 , 12 , - 6 , - 1 ] ; let N = arr . length ; document . write ( countKAverageSubarrays ( arr , N , K ) ) ;

Index/key variables: R
Accumulator variables: L, R, res, sum
Iterator variables: L, R
Javascript program:
function minimumElement ( arr , N , K ) { let minElement = arr [ 0 ] ; for ( let i = 0 ; i < N ; ++ i ) { minElement = Math . min ( minElement , arr [ i ] ) ; } let reqOperations = 0 ; for ( let i = 0 ; i < N ; ++ i ) { reqOperations += arr [ i ] - minElement ; } if ( reqOperations < K ) { K -= reqOperations ; minElement -= Math . floor ( ( K + N - 1 ) / N ) ; } return minElement ; } let arr = [ 10 , 10 , 10 , 10 ] ; let K = 7 ; let N = arr . length ; document . write ( minimumElement ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: K, minElement, reqOperations
Iterator variables: i
Javascript program:
function FractionSplit ( n , d ) { let UnitFactions = [ ] ; while ( n > 0 ) { let x = Math . floor ( ( d + n - 1 ) / n ) ; let s = " " + String ( x ) ; UnitFactions . push ( s ) ; n = n * x - d ; d = d * x ; } return UnitFactions ; } let n = 13 , d = 18 ; let res = FractionSplit ( n , d ) ; for ( let s of res ) document . write ( s + " " ) ;

Iterator variables: s
Javascript program:
function findPermutation ( N ) { var i ; var arr = new Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) { arr [ i ] = i + 1 ; } for ( i = 1 ; i < N ; i += 2 ) { var temp = arr [ i ] ; arr [ i ] = arr [ i - 1 ] ; arr [ i - 1 ] = temp ; } if ( N % 2 == 1 && N > 1 ) { var temp = arr [ N - 1 ] ; arr [ N - 1 ] = arr [ N - 2 ] ; arr [ N - 2 ] = temp ; } for ( i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } var N = 7 ; findPermutation ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function addAP ( A , Q , operations ) { for ( let Q of operations ) { let L = Q [ 0 ] , R = Q [ 1 ] , a = Q [ 2 ] , d = Q [ 3 ] curr = a for ( let i = L - 1 ; i < R ; i ++ ) { A [ i ] += curr curr += d } } for ( let i of A ) { document . write ( i + " " ) } } let A = [ 5 , 4 , 2 , 8 ] let Q = 2 let Query = [ [ 1 , 2 , 1 , 3 ] , [ 1 , 4 , 4 , 1 ] ] addAP ( A , Q , Query )

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: Q, i
Javascript program:
function maximizeNumber ( N , K ) { let s = String ( N ) ; let L = s . length ; let result = [ ] ; let i = 0 ; while ( ( i < L ) && ( K <= ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) ) { result . push ( s [ i ] ) ; ++ i ; } result . push ( String . fromCharCode ( K + ' ' . charCodeAt ( 0 ) ) ) ; while ( i < L ) { result . push ( s [ i ] ) ; ++ i ; } document . write ( result . join ( " " ) ) ; } let N = 6673 , K = 6 ; maximizeNumber ( N , K ) ;

Index/key variables: i
Javascript program:
function minimumDistance ( arr , N ) { let ind = 0 ; let prev = arr [ ind ] ; let s = arr . length ; for ( let i = 0 ; i < N ; i ++ ) { let distance = Number . MAX_SAFE_INTEGER ; if ( i < arr [ 0 ] ) { distance = arr [ 0 ] - i ; } else if ( i >= prev && ind + 1 < s && i <= arr [ ind + 1 ] ) { distance = Math . min ( i - prev , arr [ ind + 1 ] - i ) ; if ( i == arr [ ind + 1 ] ) { distance = 0 ; prev = arr [ ind + 1 ] ; ind ++ ; } } else { distance = i - prev ; } document . write ( distance + " " ) ; } } let N = 5 ; let arr = [ 0 , 4 ] ; minimumDistance ( arr , N ) ;

Index/key variables: ind
Accumulator variables: i, ind
Iterator variables: i
Javascript program:
function countOfPairs ( arr , N , X ) { let count = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( ( ( arr [ i ] ^ arr [ j ] ) & X ) == 0 ) count ++ ; } } return count ; } let arr = [ 3 , 2 , 5 , 4 , 6 , 7 ] ; let X = 6 ; let N = arr . length ; document . write ( countOfPairs ( arr , N , X ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function countOfPairs ( arr , N , X ) { let count = 0 ; let M = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( M . has ( arr [ i ] & X ) ) { M . set ( arr [ i ] & X , M . get ( arr [ i ] & X ) + 1 ) ; } else { M . set ( arr [ i ] & X , 1 ) ; } } for ( let m of M ) { let p = m [ 1 ] ; count += ( p * ( p - 1 ) ) / 2 ; } return count ; } let arr = [ 3 , 2 , 5 , 4 , 6 , 7 ] ; let X = 6 ; let N = arr . length ; document . write ( countOfPairs ( arr , N , X ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i, m
Javascript program:
let MAX = 1000 function cntMatrices ( arr , N , M , K ) { let cnt = 0 ; let pre = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( M + 1 ) . fill ( 0 ) ) for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= M ; j ++ ) { pre [ i ] [ j ] = arr [ i - 1 ] [ j - 1 ] + pre [ i - 1 ] [ j ] + pre [ i ] [ j - 1 ] - pre [ i - 1 ] [ j - 1 ] ; } } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= M ; j ++ ) { for ( let l = i , r = j ; l > 0 && r > 0 ; l -- , r -- ) { let sum1 = ( K * ( i - l + 1 ) * ( i - r + 1 ) ) ; let sum2 = pre [ i ] [ j ] - pre [ l - 1 ] [ r ] - pre [ l ] [ r - 1 ] + pre [ l - 1 ] [ r - 1 ] ; if ( sum1 <= sum2 ) cnt ++ ; } } } return cnt ; } let arr = [ [ 2 , 2 , 3 ] , [ 3 , 4 , 5 ] , [ 4 , 5 , 5 ] ] ; let K = 4 ; let N = arr . length ; let M = arr [ 0 ] . length ; document . write ( cntMatrices ( arr , N , M , K ) ) ;

Index/key variables: i, j, l, r
Accumulator variables: cnt, i, j, l, r
Iterator variables: i, j, l
Javascript program:
function ConcatenateArr ( arr , N ) { let ans = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { let l = Math . floor ( Math . log10 ( arr [ i ] ) + 1 ) ; ans = ans * Math . pow ( 10 , l ) ; ans += arr [ i ] ; } return ans ; } let arr = [ 1 , 23 , 456 ] ; let N = arr . length ; document . write ( ConcatenateArr ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function DistRecursion ( S , i , dist ) { if ( i == S . length ) return Math . abs ( dist ) ; if ( S [ i ] == ' ' ) return DistRecursion ( S , i + 1 , dist - 1 ) ; if ( S [ i ] == ' ' ) return DistRecursion ( S , i + 1 , dist + 1 ) ; return Math . max ( DistRecursion ( S , i + 1 , dist - 1 ) , DistRecursion ( S , i + 1 , dist + 1 ) ) ; } function maxDistance ( S ) { return DistRecursion ( S , 0 , 0 ) ; } let S = " " ; document . write ( maxDistance ( S ) ) ;

Index/key variables: i
Javascript program:
function findPairs ( p , q , r ) { let v = [ ] ; for ( let i = p ; i <= q ; i ++ ) { if ( i % r == 0 ) { v . push ( i ) ; } } let ans = [ ] ; for ( let i = 0 ; i < v . length ; i ++ ) { for ( let j = i + 1 ; j < v . length ; j ++ ) { if ( v [ i ] * v [ j ] >= p * q / 4 && v [ i ] * v [ j ] <= p * q ) { ans . push ( [ v [ i ] , v [ j ] ] ) ; } } } if ( ans . length == 0 ) { document . write ( - 1 + " " ) ; } else { for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] [ 0 ] + " " + ans [ i ] [ 1 ] + " " ) ; } } } let p = 14 , q = 30 , r = 5 ; findPairs ( p , q , r ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printRectPattern ( c1 , c2 , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( Math . max ( Math . abs ( c1 - i ) , Math . abs ( c2 - j ) ) + " " ) ; } document . write ( " " ) ; } } let c1 = 2 ; let c2 = 2 ; let n = 5 ; printRectPattern ( c1 , c2 , n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countNumbers ( l , r ) { let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { if ( ( i & 1 ) == 0 ) { count ++ ; } } return count ; } let l = 10 , r = 20 ; document . write ( countNumbers ( l , r ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function isPerfectSquare ( x ) { let s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function contiguousFibonacciNumber ( arr , n ) { let current_length = 0 ; let max_length = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isFibonacci ( arr [ i ] ) ) { current_length ++ ; } else { current_length = 0 ; } max_length = Math . max ( max_length , current_length ) ; } return max_length ; } let arr = [ 11 , 8 , 21 , 5 , 3 , 28 , 4 ] ; let n = arr . length ; document . write ( contiguousFibonacciNumber ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: current_length, i
Iterator variables: i
Javascript program:
let direction = [ [ - 1 , 0 ] , [ 0 , 1 ] , [ 0 , - 1 ] , [ 1 , 0 ] ] ; function dfs ( matrix , i , j , N , M ) { if ( i == N - 1 && j == M - 1 ) { return true ; } matrix [ i ] [ j ] = 1 ; for ( let k = 0 ; k < 4 ; k ++ ) { let newX = i + direction [ k ] [ 0 ] ; let newY = j + direction [ k ] [ 1 ] ; if ( newX >= 0 && newX < N && newY >= 0 && newY < M && matrix [ newX ] [ newY ] == 0 ) { if ( dfs ( matrix , newX , newY , N , M ) ) { return true ; } } } return false ; } function solve ( matrix ) { let N = matrix . length ; let M = matrix [ 0 ] . length ; if ( ! dfs ( matrix , 0 , 0 , N , M ) ) { return 0 ; } if ( ! dfs ( matrix , 0 , 0 , N , M ) ) { return 1 ; } return 2 ; } let mat = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] ; document . write ( solve ( mat ) ) ;

Index/key variables: i, j, k, newX, newY
Accumulator variables: k
Iterator variables: k
Javascript program:
function Kadane ( arr , n ) { let largestSum = 0 , currMax = 0 ; let currSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { currSum += arr [ i ] ; currMax = Math . max ( currMax , arr [ i ] ) ; largestSum = Math . max ( largestSum , currMax * currSum ) ; if ( currSum < 0 ) { currMax = 0 ; currSum = 0 ; } } return largestSum ; } function maximumWeight ( arr , n ) { let largestSum = Kadane ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = - arr [ i ] ; } largestSum = Math . max ( largestSum , Kadane ( arr , n ) ) ; return largestSum ; } let arr = [ 2 , - 3 , 8 , - 2 , 5 ] ; let N = arr . length ; document . write ( maximumWeight ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: currSum, i
Iterator variables: i
Javascript program:
function arrayPartition ( a , n ) { let ans = new Array ( n ) ; let cnt = 0 ; let ind , flag = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( a [ i ] ) ) { mp . set ( a [ i ] , mp . get ( a [ i ] ) + 1 ) } else { mp . set ( a [ i ] , 1 ) } } for ( let i = 0 ; i < n ; i ++ ) { if ( mp . get ( a [ i ] ) == 1 ) cnt ++ ; if ( mp . get ( a [ i ] ) > 2 && flag == 0 ) { flag = 1 ; ind = i ; } } let p = Math . floor ( ( cnt + 1 ) / 2 ) ; let ans1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans [ i ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . get ( a [ i ] ) == 1 && ans1 < p ) { ans [ i ] = 1 ; ans1 ++ ; } else if ( mp . get ( a [ i ] ) == 1 ) { ans [ i ] = 2 ; } } if ( cnt % 2 == 1 && flag == 0 ) { document . write ( - 1 + " " ) ; return ; } if ( cnt % 2 == 0 ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } else { for ( let i = 0 ; i < n ; i ++ ) { if ( ind == i ) document . write ( 2 + " " ) ; else document . write ( ans [ i ] << " " ) ; } } } let arr = [ 1 , 1 , 2 , 3 , 4 , 4 ] ; let N = arr . length arrayPartition ( arr , N ) ;

Index/key variables: i
Accumulator variables: ans1, cnt, i
Iterator variables: i
Javascript program:
function evenOdd ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let even_digits = 0 ; let odd_digits = 0 ; let temp = arr [ i ] ; while ( temp ) { if ( ( temp % 10 ) & 1 ) odd_digits ++ ; else even_digits ++ ; temp = parseInt ( temp / 10 ) } if ( even_digits > odd_digits ) { let res = 0 ; while ( arr [ i ] ) { res += arr [ i ] % 10 ; arr [ i ] = parseInt ( arr [ i ] / 10 ) ; } document . write ( res + " " ) ; } else if ( odd_digits > even_digits ) { let res = 1 ; while ( arr [ i ] ) { res *= arr [ i ] % 10 ; arr [ i ] = parseInt ( arr [ i ] / 10 ) } document . write ( res + " " ) ; } else document . write ( arr [ i ] + " " ) ; } } let arr = [ 113 , 141 , 214 , 3186 ] ; let N = arr . length ; evenOdd ( arr , N ) ;

Index/key variables: i
Accumulator variables: even_digits, i, odd_digits, res
Iterator variables: i
Javascript program:
function primeFactorization ( N ) { let sieve = new Array ( parseInt ( N / 2 ) + 1 ) . fill ( 0 ) ; for ( let i = 2 ; i <= N / 2 ; i ++ ) { if ( sieve [ i ] == 0 ) { for ( let j = i * i ; j <= N / 2 ; j += i ) { sieve [ j ] = 1 ; } } } let prime = [ ] ; for ( let i = 3 ; i <= N / 2 ; i ++ ) if ( sieve [ i ] == 0 ) prime . push ( i ) ; let x = prime . length ; document . write ( " " + x ) ; document . write ( " " ) for ( let i of prime ) { document . write ( i + " " ) ; document . write ( " " ) ; } } let N = 18 ; primeFactorization ( N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sumOfFirstM ( A , N , M ) { let sum = 0 ; for ( let i = 0 ; i < M ; i ++ ) { sum = sum + A [ i % N ] ; } return sum ; } let arr = [ 1 , 2 , 3 ] ; let M = 5 ; let N = arr . length ; document . write ( sumOfFirstM ( arr , N , M ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function canReach0toM ( a , n , m ) { let rightMost = new Array ( m + 1 ) ; let dp = new Array ( m + 1 ) ; for ( let i = 0 ; i <= m ; i ++ ) { rightMost [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let a1 = a [ i ] [ 0 ] ; let b1 = a [ i ] [ 1 ] ; rightMost [ a1 ] = Math . max ( rightMost [ a1 ] , b1 ) ; } for ( let i = m ; i >= 0 ; i -- ) { dp [ i ] = i ; for ( let j = Math . min ( m , rightMost [ i ] ) ; j > i ; j -- ) { dp [ i ] = Math . max ( dp [ i ] , dp [ j ] ) ; } } if ( dp [ 0 ] >= m ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ [ 0 , 2 ] , [ 2 , 2 ] , [ 2 , 5 ] , [ 4 , 5 ] ] ; let M = 5 ; let N = arr . length ; canReach0toM ( arr , N , M ) ;

Index/key variables: a1, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function countPairs ( arr , N ) { for ( var i = 0 ; i < N ; i ++ ) { var count = 0 ; for ( var x = 1 ; x <= arr [ i ] ; x ++ ) { for ( var y = x ; y <= arr [ i ] ; y ++ ) { if ( gcd ( x , y ) > 1 ) count ++ ; } } document . write ( count + " " ) ; } } var arr = [ 5 , 10 , 20 ] ; var N = 3 ; countPairs ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i, x, y
Iterator variables: i, x, y
Javascript program:
const MAX = 1005 ; function preCalculate ( phi , ans ) { phi [ 0 ] = 0 ; phi [ 1 ] = 1 ; for ( let i = 2 ; i <= MAX ; i ++ ) phi [ i ] = i ; for ( let i = 2 ; i <= MAX ; i ++ ) { if ( phi [ i ] == i ) { for ( let j = i ; j <= MAX ; j += i ) phi [ j ] -= Math . floor ( phi [ j ] / i ) ; } } for ( let i = 1 ; i <= MAX ; i ++ ) ans [ i ] = ans [ i - 1 ] + ( i - phi [ i ] ) ; } function countPairs ( arr , N ) { let phi = new Array ( 1e5 ) . fill ( 0 ) ; let ans = new Array ( 1e5 ) . fill ( 0 ) ; preCalculate ( phi , ans ) ; for ( let i = 0 ; i < N ; ++ i ) { document . write ( ans [ arr [ i ] ] + " " ) ; } } let arr = [ 5 , 10 , 20 ] ; let N = 3 ; countPairs ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumTurns ( arr , N ) { let Count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { while ( arr [ i ] % 2 == 0 ) { Count ++ ; arr [ i ] = Math . floor ( arr [ i ] / 2 ) ; } } return Count ; } let arr = [ 5 , 2 , 4 ] ; let M = 3 , K = 2 ; let N = arr . length ; document . write ( maximumTurns ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: Count, i
Iterator variables: i
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } function maxGCDInRange ( L , R ) { let ans = 1 ; for ( let Z = R ; Z >= 1 ; Z -- ) { if ( parseInt ( ( R / Z ) ) - parseInt ( ( L - 1 ) / Z ) > 1 ) { ans = Z ; break ; } } return ans ; } let L = 102 ; let R = 139 ; document . write ( maxGCDInRange ( L , R ) ) ;

Accumulator variables: Z
Iterator variables: Z
Javascript program:
function noOfWays ( N , K ) { let S = N . toString ( ) ; let ans = 1 ; for ( let i = 1 ; i < S . length ; i ++ ) { let count = 1 ; while ( i < S . length && S [ i ] . charCodeAt ( ) - 48 + S [ i - 1 ] . charCodeAt ( ) - 48 == K ) { count ++ ; i ++ ; } if ( count % 2 == 1 ) ans *= Math . floor ( ( count + 1 ) / 2 ) ; } return ans ; } let N = 1454781 ; let K = 9 ; document . write ( noOfWays ( N , K ) ) ;

Index/key variables: i
Accumulator variables: ans, count, i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } function minOperations ( A , B ) { let cnt1 = 0 , cnt2 = 0 ; cnt1 += countSetBits ( A ) ; cnt2 += countSetBits ( B ) ; if ( ( cnt1 + cnt2 ) % 2 != 0 ) return - 1 ; let oneZero = 0 , zeroOne = 0 ; let ans = 0 ; for ( let i = 0 ; i < Math . max ( cnt1 , cnt2 ) ; i ++ ) { let bitpos = 1 << i ; if ( ( ! ( bitpos & A ) ) && ( bitpos & B ) ) zeroOne ++ ; if ( ( bitpos & A ) && ( ! ( bitpos & B ) ) ) oneZero ++ ; } ans = parseInt ( zeroOne / 2 ) + parseInt ( oneZero / 2 ) ; if ( zeroOne % 2 != 0 ) ans += 2 ; return ans ; } let A = 27 , B = 5 ; document . write ( minOperations ( A , B ) ) ;

Accumulator variables: ans, cnt1, cnt2, count, i, oneZero, zeroOne
Iterator variables: i
Javascript program:
function maximumSum ( A , N , K ) { let curr_sum = 0 ; let max_sum = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < N - K + 1 ; i ++ ) { let dupl_arr = [ ... A . slice ( i , i + K ) ] ; dupl_arr . sort ( ( a , b ) => a - b ) let flag = true ; for ( let j = 1 ; j < K ; j ++ ) { if ( dupl_arr [ j ] - dupl_arr [ j - 1 ] != 1 ) { flag = false ; break ; } } if ( flag ) { let temp = 0 ; curr_sum = dupl_arr . reduce ( ( acc , cur ) => acc + cur , 0 ) max_sum = Math . max ( max_sum , curr_sum ) ; curr_sum = 0 ; } } return max_sum ; } let arr = [ 10 , 12 , 9 , 8 , 10 , 15 , 1 , 3 , 2 ] ; let K = 3 ; let N = arr . length ; document . write ( maximumSum ( arr , N , K ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
let MAX = 10000 ; let primes = new Array ( ) ; function sieveSundaram ( ) { let marked = Array . from ( { length : MAX / 2 + 100 } , ( _ , i ) => 0 ) ; for ( let i = 1 ; i <= ( Math . floor ( Math . sqrt ( MAX ) - 1 ) ) / 2 ; i ++ ) for ( let j = ( i * ( i + 1 ) ) << 1 ; j <= MAX / 2 ; j = j + 2 * i + 1 ) marked [ j ] = true ; primes . push ( 2 ) ; for ( let i = 1 ; i <= Math . floor ( MAX / 2 ) ; i ++ ) if ( marked [ i ] == false ) primes . push ( 2 * i + 1 ) ; } function isSmith ( n ) { let original_no = n ; let pDigitSum = 0 ; for ( let i = 0 ; primes [ i ] <= Math . floor ( n / 2 ) ; i ++ ) { while ( n % primes [ i ] == 0 ) { let p = primes [ i ] ; n = Math . floor ( n / p ) ; while ( p > 0 ) { pDigitSum += ( p % 10 ) ; p = Math . floor ( p / 10 ) ; } } } if ( n != 1 && n != original_no ) { while ( n > 0 ) { pDigitSum = pDigitSum + n % 10 ; n = Math . floor ( n / 10 ) ; } } let sumDigits = 0 ; while ( original_no > 0 ) { sumDigits = sumDigits + original_no % 10 ; original_no = Math . floor ( original_no / 10 ) ; } return ( pDigitSum == sumDigits ) ; } function isSmithBrotherPair ( X , Y ) { return isSmith ( X ) && isSmith ( Y ) && Math . abs ( X - Y ) == 1 ; } function countSmithBrotherPairs ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = i + 1 ; j < N ; j ++ ) { if ( isSmithBrotherPair ( A [ i ] , A [ j ] ) ) count ++ ; } return count ; } sieveSundaram ( ) ; let A = [ 728 , 729 , 28 , 2964 , 2965 ] ; let N = A . length ; document . write ( countSmithBrotherPairs ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, pDigitSum
Iterator variables: i, j