dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function onesComplement ( n , maxElement ) { let bits = Math . floor ( ( Math . log ( maxElement ) / Math . log ( 2 ) ) ) + 1 ; return ( ( 1 << bits ) - 1 ) ^ n ; } function findNumber ( arr , n ) { let res = 0 ; let maxElement = 0 ; for ( let i = 0 ; i < n ; i ++ ) { res = res ^ arr [ i ] ; if ( maxElement < arr [ i ] ) maxElement = arr [ i ] ; } res = onesComplement ( res , maxElement ) ; return ( res ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; document . write ( findNumber ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateFactorial ( N ) { var fact = Array ( N + 1 ) ; fact [ 0 ] = 1 ; for ( var i = 1 ; i <= N ; i ++ ) { fact [ i ] = fact [ i - 1 ] * i ; } return fact ; } function cntWaysSelection ( arr , N , K , L , R ) { var cntWays = 0 ; var cntNum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= L && arr [ i ] <= R ) { cntNum ++ ; } } var fact = calculateFactorial ( cntNum ) ; for ( var i = K ; i <= cntNum ; i ++ ) { cntWays += fact [ cntNum ] / ( fact [ i ] * fact [ cntNum - i ] ) ; } return cntWays ; } var arr = [ 12 , 4 , 6 , 13 , 5 , 10 ] ; var N = arr . length ; var K = 3 ; var L = 4 ; var R = 10 ; document . write ( cntWaysSelection ( arr , N , K , L , R ) ) ;

Index/key variables: cntNum, i
Accumulator variables: cntNum, cntWays, i
Iterator variables: i
Javascript program:
function TotalAndPair ( arr , N ) { let totalAND = ( 1 << 30 ) - 1 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { totalAND &= arr [ i ] & arr [ j ] ; } } return totalAND ; } let arr = [ 4 , 5 , 12 , 15 ] ; let N = arr . length ; document . write ( TotalAndPair ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, totalAND
Iterator variables: i, j
Javascript program:
function smallestDivisorGr1 ( N ) { for ( let i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { return i ; } } return N ; } function findValOfNWithOperat ( N , K ) { for ( let i = 1 ; i <= K ; i ++ ) { N += smallestDivisorGr1 ( N ) ; } return N ; } let N = 6 , K = 4 ; document . write ( findValOfNWithOperat ( N , K ) ) ;

Accumulator variables: N, i
Iterator variables: i
Javascript program:
let M = 1000000007 ; function findTripleSum ( A , B , C ) { let sum = 0 ; for ( let i = 1 ; i <= A ; i ++ ) { for ( let j = 1 ; j <= B ; j ++ ) { for ( let k = 1 ; k <= C ; k ++ ) { let prod = ( ( ( i % M ) * ( j % M ) ) % M * ( k % M ) ) % M ; sum = ( sum + prod ) % M ; } } } return sum ; } let A = 10 ; let B = 100 ; let C = 1000 ; document . write ( findTripleSum ( A , B , C ) ) ;

Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function getMaximum ( N , M , mat ) { let global_max = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { let row_min = Number . MAX_VALUE ; for ( let k = 0 ; k < M ; k ++ ) { let m = Math . max ( mat [ i ] [ k ] , mat [ j ] [ k ] ) ; row_min = Math . min ( row_min , m ) ; } global_max = Math . max ( global_max , row_min ) ; } } return global_max ; } let mat = [ [ 5 , 0 , 3 , 1 , 2 ] , [ 1 , 8 , 9 , 1 , 3 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 9 , 1 , 0 , 3 , 7 ] , [ 2 , 3 , 0 , 6 , 3 ] , [ 6 , 4 , 1 , 7 , 0 ] ] ; let N = 6 , M = 5 ; document . write ( getMaximum ( N , M , mat ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function makeTree ( tree , edges , N ) { for ( var i = 0 ; i < N - 1 ; i ++ ) { var u = edges [ i ] [ 0 ] ; var v = edges [ i ] [ 1 ] ; tree [ u ] . push ( v ) ; } } function dfs ( node , tree ) { var mex = 0 ; var size = 1 ; tree [ node ] . forEach ( u => { var temp = dfs ( u , tree ) ; mex = Math . max ( mex , temp [ 0 ] ) ; size += temp [ 1 ] ; } ) ; return [ mex + size , size ] ; } var N = 7 ; var edges = [ [ 1 , 4 ] , [ 1 , 5 ] , [ 5 , 2 ] , [ 5 , 3 ] , [ 4 , 7 ] , [ 7 , 6 ] ] ; var tree = Array . from ( Array ( N + 1 ) , ( ) => Array ( ) ) ; makeTree ( tree , edges , N ) ; document . write ( dfs ( 1 , tree ) [ 0 ] ) ;

Index/key variables: i, node, u
Accumulator variables: i, size
Iterator variables: i
Javascript program:
function divisorCount ( n ) { let x = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == n / i ) x ++ ; else x += 2 ; } } return x ; } function minvalue_y ( x ) { let a = divisorCount ( x ) ; let y = x + 1 ; while ( ( a & 1 ) == ( divisorCount ( y ) & 1 ) ) y ++ ; return y ; } let x = 5 ; document . write ( minvalue_y ( x ) ) ;

Accumulator variables: i, x, y
Iterator variables: i
Javascript program:
function minStartValue ( nums ) { let minValue = 0 ; let sum = 0 ; for ( let n = 0 ; n < nums . length ; n ++ ) { sum += nums [ n ] ; minValue = Math . min ( minValue , sum ) ; } let startValue = 1 - minValue ; return startValue ; } let nums = [ - 3 , 2 , - 3 , 4 , 2 ] ; document . write ( minStartValue ( nums ) ) ;

Index/key variables: n
Accumulator variables: n, sum
Iterator variables: n
Javascript program:
function countSubArrayRemove ( arr , N ) { let prefix_element_count = new Map ( ) ; let suffix_element_count = new Map ( ) ; let total_sum_of_elements = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { total_sum_of_elements += arr [ i ] ; if ( ! suffix_element_count . has ( arr [ i ] ) ) suffix_element_count . set ( arr [ i ] , 1 ) ; else suffix_element_count . set ( arr [ i ] , suffix_element_count . get ( arr [ i ] ) + 1 ) ; } let prefix_sum = 0 ; let suffix_sum = 0 ; let count_subarray_equal_sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { prefix_sum += arr [ i ] ; if ( ! prefix_element_count . has ( arr [ i ] ) ) prefix_element_count . set ( arr [ i ] , 1 ) ; else prefix_element_count . set ( arr [ i ] , prefix_element_count . get ( arr [ i ] ) + 1 ) ; suffix_sum = total_sum_of_elements - prefix_sum ; if ( ! suffix_element_count . has ( arr [ i ] ) ) suffix_element_count . set ( arr [ i ] , 0 ) ; else suffix_element_count . set ( arr [ i ] , suffix_element_count . get ( arr [ i ] ) - 1 ) ; let difference = prefix_sum - suffix_sum ; let number_of_subarray_at_i_split = 0 ; if ( prefix_element_count . has ( difference ) ) number_of_subarray_at_i_split = prefix_element_count . get ( difference ) ; if ( suffix_element_count . has ( - difference ) ) number_of_subarray_at_i_split += suffix_element_count . get ( - difference ) ; count_subarray_equal_sum += number_of_subarray_at_i_split ; } return count_subarray_equal_sum ; } let arr = [ 1 , 2 , 1 , 1 , 3 , 1 ] ; let N = arr . length ; document . write ( countSubArrayRemove ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count_subarray_equal_sum, i, number_of_subarray_at_i_split, prefix_sum, total_sum_of_elements
Iterator variables: i
Javascript program:
function countXORSetBitsAdjElemRange1_N ( N ) { let total_set_bits = 0 ; let bit_Position = 1 ; while ( N ) { total_set_bits += ( Math . floor ( ( N + 1 ) / 2 ) * bit_Position ) ; N -= Math . floor ( ( N + 1 ) / 2 ) ; bit_Position ++ ; } return total_set_bits ; } let N = 4 ; document . write ( countXORSetBitsAdjElemRange1_N ( N ) ) ;

Accumulator variables: N, bit_Position, total_set_bits
Javascript program:
function checkPerfectSquare ( N ) { if ( N <= 0 ) { return 0 ; } let sq = Math . sqrt ( N ) ; if ( Math . floor ( sq ) == Math . ceil ( sq ) ) { return 1 ; } return 0 ; } function checktwoSidesareRighTriangle ( A , B ) { let checkTriangle = false ; if ( checkPerfectSquare ( A * A + B * B ) != 0 ) { checkTriangle = true ; } if ( checkPerfectSquare ( A * A - B * B ) != 0 ) { checkTriangle = true ; } if ( checkPerfectSquare ( B * B - A * A ) != 0 ) { checkTriangle = true ; } return checkTriangle ; } let A = 3 , B = 4 ; if ( checktwoSidesareRighTriangle ( A , B ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Boolean variables: checkTriangle
Javascript program:
function array_sum ( arr , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } function countOperations ( arr , N ) { var count_zeros = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) count_zeros ++ ; } var sum = array_sum ( arr , N ) ; if ( count_zeros != 0 ) return count_zeros ; if ( sum == 0 ) return 1 ; return 0 ; } var arr = [ - 1 , - 1 , 0 , 0 ] ; var N = arr . length ; document . write ( countOperations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count_zeros, i, sum
Iterator variables: i
Javascript program:
function TotalBitwiseORPair ( arr , N ) { let totalOR = 0 ; for ( let i = 0 ; i < N ; i ++ ) { totalOR |= arr [ i ] ; } return totalOR ; } let arr = [ 4 , 5 , 12 , 15 ] ; let N = arr . length ; document . write ( TotalBitwiseORPair ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, totalOR
Iterator variables: i
Javascript program:
function printFinalArray ( a , n , operations , p , capacity ) { var i , curr = 0 ; var picked = false ; for ( i = 0 ; i < p ; i ++ ) { var s = operations [ i ] ; var flag = false ; switch ( s ) { case 1 : if ( curr != 0 ) curr -- ; break ; case 2 : if ( curr != n - 1 ) curr ++ ; break ; case 3 : if ( picked == false && a [ curr ] != 0 ) { picked = true ; a [ curr ] -- ; } break ; case 4 : if ( picked == true && a [ curr ] != capacity ) { picked = false ; a [ curr ] ++ ; } break ; default : flag = true ; } if ( flag == true ) break ; } for ( i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } var capacity = 5 ; var a = [ 2 , 5 , 2 ] ; var N = a . length ; var operations = [ 3 , 2 , 4 , 1 , 4 , 5 ] ; var M = operations . length ; printFinalArray ( a , N , operations , M , capacity ) ;

Index/key variables: curr, i
Accumulator variables: curr, i
Iterator variables: i
Boolean variables: flag, picked
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 ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function CheckSumPrime ( A , N ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let s = new String ( A [ i ] ) ; sum += s . length ; } if ( isPrime ( sum ) ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let A = [ 1 , 11 , 12 ] ; let N = A . length CheckSumPrime ( A , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function checkPalindrome ( N ) { let rev = 0 ; let temp = N ; while ( N != 0 ) { rev = Math . floor ( rev * 10 + N % 10 ) ; N = Math . floor ( N / 10 ) ; } N = temp ; if ( N == rev ) { return true ; } return false ; } function closestSmallerPalindrome ( N ) { do { N -- ; } while ( N >= 0 && ! checkPalindrome ( N ) ) ; return N ; } let N = 4000 ; document . write ( closestSmallerPalindrome ( N ) ) ;

Accumulator variables: N
Javascript program:
function MinimumOperationReq ( N ) { let cntDecr = 0 ; let temp = N ; while ( temp > 0 ) { let X = Math . floor ( Math . sqrt ( temp ) ) ; if ( X * X == temp ) { break ; } temp = temp - 2 ; cntDecr += 1 ; } let cntIncr = 0 ; while ( true ) { let X = Math . floor ( Math . sqrt ( N ) ) ; if ( X * X == N ) { break ; } N = N + 2 ; cntIncr += 1 ; } return Math . min ( cntIncr , cntDecr ) ; } let N = 15 ; document . write ( MinimumOperationReq ( N ) ) ;

Accumulator variables: cntDecr, cntIncr
Javascript program:
function add ( arr , x ) { arr . push ( x ) ; } function update ( effect , x ) { effect = effect ^ x ; return effect ; } function computeResults ( arr , effect ) { for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = arr [ i ] ^ effect ; document . write ( arr [ i ] + " " ) ; } } let arr = [ 0 ] ; let effect = 0 ; add ( arr , 5 ) ; effect = update ( effect , 2 ) computeResults ( arr , effect ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSubArray ( arr , k ) { var ans = [ ] ; var i , sum = 0 ; for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } var found = 0 ; if ( sum % 3 == 0 ) { ans = [ 0 , i - 1 ] ; found = 1 ; } for ( var j = i ; j < arr . length ; j ++ ) { if ( found == 1 ) break ; sum = sum + arr [ j ] - arr [ j - k ] ; if ( sum % 3 == 0 ) { ans = [ j - k + 1 , j ] ; found = 1 ; } } if ( found == 0 ) ans = [ - 1 , 0 ] ; if ( ans . first == - 1 ) { cout << - 1 ; } else { for ( i = ans [ 0 ] ; i <= ans [ 1 ] ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } } var arr = [ 84 , 23 , 45 , 12 , 56 , 82 ] ; var K = 3 ; findSubArray ( arr , K ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function calculateFact ( fact , N ) { fact [ 0 ] = 1 ; for ( var i = 1 ; i < N ; i ++ ) { fact [ i ] = fact [ i - 1 ] * i ; } } function nCr ( fact , N , R ) { if ( R > N ) return 0 ; var res = parseInt ( fact [ N ] / fact [ R ] ) ; res = parseInt ( res / fact [ N - R ] ) ; return res ; } function countWays ( arr , fact ) { var N = arr . length ; if ( N <= 2 ) { return 1 ; } var leftSubTree = [ ] ; var rightSubTree = [ ] ; var root = arr [ 0 ] ; for ( var i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < root ) { leftSubTree . push ( arr [ i ] ) ; } else { rightSubTree . push ( arr [ i ] ) ; } } var N1 = leftSubTree . length ; var N2 = rightSubTree . length ; var countLeft = countWays ( leftSubTree , fact ) ; var countRight = countWays ( rightSubTree , fact ) ; return nCr ( fact , N - 1 , N1 ) * countLeft * countRight ; } var arr = [ ] ; arr = [ 3 , 4 , 5 , 1 , 2 ] ; var N = arr . length ; var fact = Array ( N ) ; calculateFact ( fact , N ) ; document . write ( countWays ( arr , fact ) ) ;

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

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let mod = 1e9 + 7 ; function NthTerm ( F , C , K , n ) { let ans = new Uint8Array ( n + 1 ) ; for ( let i = 0 ; i < K ; i ++ ) ans [ i ] = F [ i ] ; for ( let i = K ; i <= n ; i ++ ) { for ( let j = i - K ; j < i ; j ++ ) { ans [ i ] += ans [ j ] ; ans [ i ] %= mod ; } } document . write ( ans [ n ] + " " ) ; } let F = [ 0 , 1 ] ; let C = [ 1 , 1 ] ; let K = 2 ; let N = 10 ; NthTerm ( F , C , K , N ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countFreq ( arr , n ) { let mp1 = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( mp1 . has ( arr [ i ] ) ) { mp1 . set ( arr [ i ] , mp1 . get ( arr [ i ] ) + 1 ) ; } else { mp1 . set ( arr [ i ] , 1 ) ; } } let mp2 = new Map ( ) ; for ( let [ key , value ] of mp1 . entries ( ) ) { if ( mp2 . has ( value ) ) { mp2 . set ( value , mp2 . get ( value ) + 1 ) ; } else { mp2 . set ( value , 1 ) ; } } let M = Number . MIN_VALUE ; for ( let [ key , value ] of mp2 . entries ( ) ) { M = Math . max ( M , value ) ; } for ( let [ key , value ] of mp2 . entries ( ) ) { if ( M == value ) { return key ; } } return 0 ; } let arr = [ 6 , 10 , 3 , 10 , 8 , 3 , 6 , 4 ] ; let n = arr . length ; document . write ( countFreq ( arr , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function maxDisconnected ( N , E ) { let curr = 1 ; let rem = E ; while ( rem > 0 ) { rem = rem - Math . min ( curr , rem ) ; curr ++ ; } if ( curr > 1 ) { return N - curr ; } else { return N ; } } let N = 5 , E = 1 ; document . write ( maxDisconnected ( N , E ) ) ;

Accumulator variables: curr
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function findProduct ( N ) { var result = 1 ; for ( var i = 2 ; i < N ; i ++ ) { if ( gcd ( i , N ) == 1 ) { result *= i ; } } return result ; } var N = 5 ; document . write ( findProduct ( N ) )

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function countPairs ( A , B , N , M , List ) { var count = 0 ; var par = Array ( N + 1 ) ; for ( var i = 0 ; i <= N ; i ++ ) par [ i ] = i ; for ( var i = 0 ; i < M ; i ++ ) { var index1 = find ( par , List [ i ] [ 0 ] - 1 ) ; var index2 = find ( par , List [ i ] [ 1 ] - 1 ) ; if ( index1 != index2 ) { unionn ( par , index1 , index2 ) ; } } var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { mp . set ( A [ i ] , i ) ; } for ( var i = 0 ; i < N ; i ++ ) { if ( A [ i ] != B [ i ] ) { if ( ! mp . has ( B [ i ] ) ) { count ++ ; continue ; } var j = mp . get ( B [ i ] ) ; if ( find ( par , i ) != find ( par , j ) ) count ++ ; } } return count ; } function find ( par , x ) { if ( par [ x ] == x ) return x ; else return par [ x ] = find ( par , par [ x ] ) ; } function unionn ( par , a , b ) { a = find ( par , a ) ; b = find ( par , b ) ; if ( a == b ) return ; par [ a ] = b ; } var N = 5 ; var M = 4 ; var A = [ 1 , 5 , 9 , 2 , 3 ] ; var B = [ 2 , 4 , 5 , 1 , 3 ] ; var List = [ [ 1 , 4 ] , [ 2 , 3 ] , [ 3 , 5 ] , [ 2 , 5 ] ] ; document . write ( countPairs ( A , B , N , M , List ) ) ;

Index/key variables: a, i, x
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function max_valid_triplet ( A , n ) { let ans = - 1 ; for ( let i = 0 ; i < n - 2 ; i ++ ) { for ( let j = i + 1 ; j < n - 1 ; j ++ ) { for ( let k = j + 1 ; k < n ; k ++ ) { if ( A [ i ] < A [ j ] && A [ j ] < A [ k ] ) { let value = A [ i ] + A [ j ] * A [ k ] ; if ( value > ans ) { ans = value ; } } } } } document . write ( ans ) ; } let arr = [ 7 , 9 , 3 , 8 , 11 , 10 ] ; let n = arr . length ; max_valid_triplet ( arr , n ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
mod = 1000000007 ans = Array ( 100002 ) . fill ( 1 ) function preCompute ( ) { for ( var i = 2 ; i <= 100000 / 2 ; i ++ ) { for ( var j = 2 * i ; j <= 100000 ; j += i ) { ans [ j ] = ( ans [ j ] * i ) % mod ; } } } function productOfProperDivi ( num ) { return ans [ num ] ; } preCompute ( ) ; var queries = 5 ; var a = [ 4 , 6 , 8 , 16 , 36 ] ; for ( var i = 0 ; i < queries ; i ++ ) { document . write ( productOfProperDivi ( a [ i ] ) + " " ) ; }

Index/key variables: i, j, num
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findlcm ( n ) { let ans = 1 ; for ( let i = 1 ; i <= n ; i ++ ) ans = ( ( ( i * ans ) ) / ( __gcd ( i , ans ) ) ) ; return ans ; } function highestPower ( n ) { let lcm = findlcm ( n ) ; let ans = 0 ; for ( let i = 1 ; ; i ++ ) { let x = Math . pow ( 2 , i ) ; if ( lcm % x == 0 ) { ans = i ; } if ( x > n ) break ; } return ans ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let n = 15 ; document . write ( highestPower ( n ) ) ;

Accumulator variables: i
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 ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function deleteIth ( str , i ) { str = str . substr ( 0 , i ) + str . substr ( i + 1 ) ; return str ; } function isPrimePossible ( N ) { let s = N . toString ( ) ; let l = s . length ; if ( l < 2 ) return false ; for ( let i = 0 ; i < l ; i ++ ) { let str = deleteIth ( s , i ) ; let num = parseInt ( str ) ; if ( isPrime ( num ) ) return true ; } return false ; } let N = 610 ; if ( isPrimePossible ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkFactors ( N ) { let ev_count = 0 , od_count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) { if ( i == Math . floor ( N / i ) ) { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } else { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; if ( Math . floor ( N / i ) % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } } } if ( ev_count % 2 == 0 && od_count % 2 == 1 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let N = 36 ; checkFactors ( N ) ;

Accumulator variables: ev_count, i, od_count
Iterator variables: i
Javascript program:
function gcd ( x , y ) { if ( x % y == 0 ) return y ; else return gcd ( y , x % y ) ; } function countPairwiseCoprime ( N , M ) { let answer = 1 ; let g = gcd ( N , M ) ; let temp = g ; for ( let i = 2 ; i * i <= g ; i ++ ) { if ( temp % i == 0 ) { answer ++ ; while ( temp % i == 0 ) temp /= i ; } } if ( temp != 1 ) answer ++ ; return answer ; } function countCoprimePair ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( countPairwiseCoprime ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) + " " ) ; } } let arr = [ [ 12 , 18 ] , [ 420 , 660 ] ] ; let N = arr . length ; countCoprimePair ( arr , N ) ;

Index/key variables: i
Accumulator variables: answer, i, temp
Iterator variables: i
Javascript program:
function getProduct ( a , n ) { var p = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { p *= Math . abs ( a [ i ] - a [ j ] ) ; } } return p ; } var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; document . write ( getProduct ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, p
Iterator variables: i, j
Javascript program:
function print ( N ) { for ( let i = 0 ; i < 100000 ; i ++ ) { if ( parseInt ( Math . pow ( i + 1 , 3 ) , 10 ) - parseInt ( Math . pow ( i , 3 ) , 10 ) == N ) { document . write ( i + " " + ( i + 1 ) ) ; return ; } } } function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function diffCube ( N ) { return isPerfectSquare ( 12 * N - 3 ) ; } let N = 19 ; if ( diffCube ( N ) != 0 ) { document . write ( " " + " " ) ; print ( N ) ; } else { document . write ( " " ) ; }

Accumulator variables: i
Iterator variables: i
Javascript program:
function findSum ( arr , n , left , right ) { let k = right - left + 1 ; let d = arr [ 1 ] / arr [ 0 ] ; let ans = arr [ left - 1 ] ; if ( d == 1 ) ans = ans * d * k ; else ans = ans * ( Math . pow ( d , k ) - 1 / ( d - 1 ) ) ; return ans ; } let arr = [ 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 ] ; let queries = 3 ; let q = [ [ 2 , 4 ] , [ 2 , 6 ] , [ 5 , 8 ] ] ; 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 Find_min ( diff_mod , count_mod , k ) { let min_oprn = Number . MAX_VALUE ; let oprn = 0 ; for ( let x = 0 ; x < k ; x ++ ) { oprn = 0 ; for ( let w of diff_mod . values ( ) ) { if ( w != x ) { if ( w == 0 ) { oprn += Math . min ( x , k - x ) * count_mod . get ( w ) ; } else { oprn += Math . min ( Math . abs ( x - w ) , k + x - w ) * count_mod . get ( w ) ; } } } if ( oprn < min_oprn ) min_oprn = oprn ; } return min_oprn ; } function Cal_min ( arr , n , k ) { let diff_mod = new Set ( ) ; let count_mod = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { diff_mod . add ( arr [ i ] % k ) ; if ( count_mod . has ( ( arr [ i ] % k ) ) ) count_mod . set ( arr [ i ] % k , count_mod . get ( arr [ i ] % k ) + 1 ) ; else count_mod . set ( arr [ i ] % k , 1 ) ; } return Find_min ( diff_mod , count_mod , k ) ; } let arr = [ 2 , 35 , 48 , 23 , 52 ] ; let n = arr . length ; let k = 3 ; document . write ( Cal_min ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, oprn, x
Iterator variables: i, w, x
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function findlcm ( arr , n ) { let ans = 1 ; for ( let i = 1 ; i <= n ; i ++ ) ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) ) ; return ans ; } function minimumSteps ( arr , n ) { let i ; let dat = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; for ( i = 1 ; i <= n ; i ++ ) dat [ arr [ i - 1 ] ] = i ; let b = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; let j = 0 , c ; for ( i = 1 ; i <= n ; i ++ ) { c = 1 ; j = dat [ i ] ; while ( j != i ) { c ++ ; j = dat [ j ] ; } b [ i ] = c ; } document . write ( findlcm ( b , n ) ) ; } let arr = [ 5 , 1 , 4 , 3 , 2 , 7 , 6 ] ; let N = arr . length ; minimumSteps ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: c, i
Iterator variables: i