dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function Pairs ( C ) { var ans = [ ] ; for ( var i = 1 ; i < C ; i ++ ) { for ( var j = i + 1 ; j < C ; j ++ ) { if ( ( i * i ) + ( j * j ) == ( C * C ) ) { ans . push ( [ i , j ] ) ; } } } return ans ; } var C = 13 ; var ans = Pairs ( C ) ; if ( ans . length == 0 ) { document . write ( " " ) ; } ans . forEach ( x => { document . write ( " " + x [ 0 ] + " " + x [ 1 ] + " " + " " ) ; } ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function factorize ( N ) { var count = 0 ; var cnt = 0 ; while ( ( N % 2 ) == 0 ) { N = N / 2 ; count ++ ; } cnt = cnt + count ; for ( i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } cnt = cnt + count ; } if ( N > 2 ) cnt = cnt + 1 ; return cnt ; } function ifNumberExists ( X , Y ) { var C , dsum ; C = X - Y - 1 ; dsum = factorize ( X ) ; if ( dsum >= C ) document . write ( " " ) ; else document . write ( " " ) ; } var X , Y ; X = 6 ; Y = 4 ; ifNumberExists ( X , Y ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
let max = 10000000 ; let prime = new Array ( max ) ; function SieveOfEratosthenes ( maxm ) { prime [ 0 ] = prime [ 1 ] = true ; for ( let i = 2 ; i * i <= maxm ; i ++ ) { if ( ! prime [ i ] ) { for ( let j = i * i ; j <= maxm ; j += i ) { prime [ j ] = true ; } } } } function print_nearest_prime ( arr , N ) { let maxm = Math . max ( ... arr ) ; SieveOfEratosthenes ( maxm ) ; let primes = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! prime [ arr [ i ] ] ) primes . push ( i ) ; } if ( primes . length == 0 ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( - 1 + " " ) ; } return ; } let curr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( curr == primes . length - 1 || i <= primes [ curr ] ) { document . write ( arr [ primes [ curr ] ] + " " ) ; continue ; } if ( Math . abs ( primes [ curr ] - i ) < Math . abs ( primes [ curr + 1 ] - i ) ) { document . write ( arr [ primes [ curr ] ] + " " ) ; } else { curr ++ ; document . write ( arr [ primes [ curr ] ] + " " ) ; } } } let N = 6 ; let arr = [ 8 , 7 , 12 , 15 , 3 , 11 ] ; print_nearest_prime ( arr , N ) ;

Index/key variables: curr, i, j
Accumulator variables: curr, i, j
Iterator variables: i, j
Javascript program:
function findPosition ( n ) { var i = 0 ; var pos = 0 ; while ( n > 0 ) { if ( n % 10 == 7 ) { pos = pos + parseInt ( Math . pow ( 2 , i + 1 ) ) ; } else { pos = pos + parseInt ( Math . pow ( 2 , i ) ) ; } i ++ ; n = parseInt ( n / 10 ) ; } document . write ( pos ) ; } var N = 777 ; findPosition ( N ) ;

Accumulator variables: i
Javascript program:
function findNumberL ( n ) { if ( n == 1 ) return " " ; let result = " " ; let length = Math . floor ( Math . log10 ( n ) + 1 ) ; for ( let i = 1 ; i <= n - ( 2 * length ) ; i ++ ) { result += ' ' ; } result = n . toString ( ) + result + n . toString ( ) ; return result ; } function findNumberS ( n ) { if ( n == 1 ) return " " ; let result = " " ; let length = Math . floor ( Math . log10 ( n ) + 1 ) ; for ( let i = 1 ; i <= n - ( 2 * length ) ; i ++ ) { result += ' ' ; } result = n . toString ( ) + result + n . toString ( ) ; return result ; } let N = 3 ; document . write ( " " + findNumberS ( N ) + " " ) ; document . write ( " " + findNumberL ( N ) ) ;

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function canReplace ( array , n ) { var i = 0 , count = 0 ; while ( i < n ) { if ( array [ i ] == 0 && ( i == 0 array [ i - 1 ] == 0 ) && ( i == n - 1 array [ i + 1 ] == 0 ) ) { array [ i ] = 1 ; count ++ ; } i ++ ; } return count ; } array = [ 1 , 0 , 0 , 0 , 1 ] document . write ( canReplace ( array , 5 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Javascript program:
function solve ( n , vec ) { let a = [ ] ; let b = [ ] ; for ( let pr = 0 ; pr < vec . length ; pr ++ ) { a . push ( vec [ pr ] [ 0 ] ) ; b . push ( vec [ pr ] [ 1 ] ) ; } a . sort ( function ( c , d ) { return c - d ; } ) ; b . sort ( function ( c , d ) { return c - d ; } ) ; let left , right , ans ; if ( ( n & 1 ) != 0 ) { left = a [ Math . floor ( n / 2 ) ] ; right = b [ Math . floor ( n / 2 ) ] ; ans = right - left + 1 ; } else { left = ( a [ Math . floor ( n / 2 ) ] + a [ Math . floor ( n / 2 ) - 1 ] ) ; right = ( b [ Math . floor ( n / 2 ) ] + b [ Math . floor ( n / 2 ) - 1 ] ) ; ans = right - left + 1 ; } document . write ( ans ) ; } let N = 3 ; let vec = [ ] ; vec . push ( [ 100 , 100 ] ) ; vec . push ( [ 10 , 10000 ] ) ; vec . push ( [ 1 , 1000000000 ] ) ; solve ( N , vec ) ;

Index/key variables: pr
Accumulator variables: pr
Iterator variables: pr
Javascript program:
let mp = new Map ( ) ; function find_pairs ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . set ( arr [ i ] , 1 ) ; } } for ( let [ key , value ] of mp . entries ( ) ) { let count = value ; if ( count > 1 ) { ans += ( ( count * ( count - 1 ) ) / 2 ) ; } } return ans ; } let arr = [ 1 , 2 , 3 , 3 , 4 , 5 , 5 , 7 , 8 ] ; let arr_size = arr . length ; document . write ( find_pairs ( arr , arr_size ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function getParity ( n , A ) { for ( let x in A ) { if ( ( x & 1 ) == 1 ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let N = 3 ; let A = [ 2 , 3 , 1 ] ; getParity ( N , A ) ;

Iterator variables: x
Javascript program:
function Maxlength ( arr , N ) { let zeroindex = Array . from ( { length : 20000 } , ( _ , i ) => 0 ) ; let maxlen ; let size = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zeroindex [ size ++ ] = i ; } if ( size == 0 ) { maxlen = N ; } else { maxlen = zeroindex [ 0 ] ; for ( let i = 0 ; i < size ; i ++ ) { if ( zeroindex [ i + 1 ] - zeroindex [ i ] - 1 > maxlen ) { maxlen = zeroindex [ i + 1 ] - zeroindex [ i ] - 1 ; } } if ( N - zeroindex [ size - 1 ] - 1 > maxlen ) { maxlen = N - zeroindex [ size - 1 ] - 1 ; } } document . write ( maxlen ) ; } let N = 9 ; let arr = [ 7 , 1 , 0 , 1 , 2 , 0 , 9 , 2 , 1 ] ; Maxlength ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, size
Iterator variables: i
Javascript program:
function isPossible ( arr , N , K ) { let oddCount = 0 , evenCount = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { evenCount ++ ; } else { oddCount ++ ; } } if ( evenCount == N || ( oddCount == N && K % 2 == 0 ) || ( K == N && oddCount % 2 == 0 ) ) { return false ; } else { return true ; } } let arr = [ 1 , 2 , 3 , 4 , 5 , 8 ] ; let K = 5 ; let N = arr . length ; if ( isPossible ( arr , N , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: evenCount, i, oddCount
Iterator variables: i
Javascript program:
function lastTwoDigits ( N ) { if ( N >= 10 ) { cout << " " ; return ; } let fac = 1 ; for ( let i = 1 ; i <= N ; i ++ ) fac = ( fac * i ) % 100 ; document . write ( fac ) ; } let N = 7 ; lastTwoDigits ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( n ) { for ( var x = 1 ; x <= Math . sqrt ( n ) ; x ++ ) { if ( n % x == 0 ) { var small = x ; var big = n / x ; if ( small % 2 == big % 2 ) { var a = ( small + big ) / 2 ; var b = ( big - small ) / 2 ; document . write ( a + " " + b ) ; return ; } } } document . write ( - 1 ) ; } var n = 7 ; solve ( n ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function commonSubarrays ( A , B , N ) { let Map = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) Map [ A [ i ] ] = i ; for ( let i = 0 ; i < N ; i ++ ) { B [ i ] = Map [ B [ i ] ] ; } let count = 0 ; let i = 0 , K ; while ( i < N ) { K = 1 ; i += 1 ; while ( i < N && B [ i ] == B [ i - 1 ] + 1 ) { i += 1 ; K += 1 ; } count = count + ( ( K ) * ( K + 1 ) ) / 2 ; } return count ; } let N = 3 ; let A = [ 1 , 2 , 3 ] ; let B = [ 2 , 3 , 1 ] ; document . write ( commonSubarrays ( A , B , N ) ) ; document . write ( " " ) ; N = 5 ; let C = [ 1 , 2 , 3 , 4 , 5 ] ; let D = [ 2 , 3 , 1 , 4 , 5 ] ; document . write ( commonSubarrays ( C , D , N ) ) ;

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
Javascript program:
function getArrayOfSizeK ( n , k ) { let ans = [ ] ; let odd = n - ( ( k - 1 ) * 1 ) ; if ( odd > 0 && odd % 2 != 0 ) { for ( let i = 0 ; i < k - 1 ; i ++ ) { ans . push ( 1 ) ; } ans . push ( odd ) ; } let even = n - ( ( k - 1 ) * 2 ) ; if ( even > 0 && even % 2 == 0 && ans . length == 0 ) { for ( let i = 0 ; i < k - 1 ; i ++ ) { ans . push ( 2 ) ; } ans . push ( even ) ; } if ( ans . length > 0 ) { for ( let i = 0 ; i < k ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } else { document . write ( " " ) ; } } let n = 10 , k = 3 ; getArrayOfSizeK ( n , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function inv ( a , m ) { let m0 = m , t , q ; let x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = Math . floor ( a / m ) ; t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } function derivative ( x ) { return 3 * x * x ; } function Image ( x , k ) { return x * x * x - k ; } function next_power ( a_t , t , a1 , prime , k ) { let power_p = Math . floor ( Math . pow ( prime , t + 1 ) ) ; let next_a = ( a_t - Image ( a_t , k ) * inv ( derivative ( a1 ) , prime ) ) % power_p ; if ( next_a < 0 ) return next_a += power_p ; return next_a ; } function powerOfPrime ( prime , power , k , a1 ) { if ( derivative ( a1 ) != 0 ) { let a_t = a1 ; for ( let p = 1 ; p < power ; p ++ ) { a_t = next_power ( a_t , p , a1 , prime , k ) ; } return a_t ; } return - 1 ; } let prime = 7 , a1 = 3 ; let power = 2 , k = 3 ; document . write ( powerOfPrime ( prime , power , k , a1 ) ) ;

Accumulator variables: next_a, p, x1
Iterator variables: p
Javascript program:
function minLCM ( arr , n ) { var mx = 0 ; for ( var i = 0 ; i < n ; i ++ ) { mx = Math . max ( mx , arr [ i ] ) ; } var mul = Array . from ( Array ( mx + 1 ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mul [ arr [ i ] ] . length > 1 ) { continue ; } mul [ arr [ i ] ] . push ( arr [ i ] ) ; } for ( var i = 1 ; i <= mx ; i ++ ) { for ( var j = i + i ; j <= mx ; j += i ) { if ( mul [ i ] . length > 1 ) { break ; } mul [ j ] . forEach ( k => { if ( mul [ i ] . length <= 1 ) { mul [ i ] . push ( k ) ; } } ) ; } } var ans = 1000000000 ; for ( var i = 1 ; i <= mx ; i ++ ) { if ( mul [ i ] . length <= 1 ) continue ; var a = mul [ i ] [ 0 ] , b = mul [ i ] [ 1 ] ; var lcm = ( a * b ) / i ; ans = Math . min ( ans , lcm ) ; } return ans ; } var arr = [ 2 , 4 , 3 , 6 , 5 ] ; var n = arr . length ; document . write ( minLCM ( arr , n ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isSuffix ( s1 , s2 ) { var n1 = s1 . length ; var n2 = s2 . length ; if ( n1 > n2 ) return false ; for ( var i = 0 ; i < n1 ; i ++ ) if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) return false ; return true ; } function CheckBinaryEquivalent ( N ) { var B_Number = 0 ; var cnt = 0 ; while ( N != 0 ) { var rem = N % 2 ; var c = Math . pow ( 10 , cnt ) ; B_Number += rem * c ; N = Math . floor ( N / 2 ) ; cnt ++ ; } console . log ( B_Number ) ; var bin = B_Number . toString ( ) ; return isSuffix ( " " , bin ) ; } var N = 9 ; if ( CheckBinaryEquivalent ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: B_Number, cnt, i
Iterator variables: i
Javascript program:
function get_divisors ( A ) { var ans = [ ] ; ans . push ( 1 ) ; for ( var i = 2 ; i <= Math . sqrt ( A ) ; i ++ ) { if ( A % i == 0 ) { ans . push ( i ) ; if ( ( i * i ) != A ) ans . push ( parseInt ( A / i ) ) ; } } return ans ; } function Sum_Possible ( set , sum ) { var n = set . length ; var subset = Array . from ( Array ( n + 1 ) , ( ) => Array ( sum + 1 ) ) ; for ( var i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( var i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= sum ; j ++ ) { if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } function Is_Practical ( A ) { var divisors = [ ] ; divisors = get_divisors ( A ) ; for ( var i = 2 ; i < A ; i ++ ) { if ( Sum_Possible ( divisors , i ) == false ) return false ; } return true ; } function print_practica_No ( A , B ) { for ( var i = A ; i <= B ; i ++ ) { if ( Is_Practical ( i ) == true ) { document . write ( i + " " ) ; } } } var A = 1 , B = 100 ; print_practica_No ( A , B ) ;

Index/key variables: i, j, n, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxDivision ( arr , n ) { arr . sort ( ( a , b ) => b - a ) ; let mxdiv = arr [ 1 ] ; for ( let i = 2 ; i < n ; ++ i ) mxdiv = mxdiv / arr [ i ] ; return arr [ 0 ] / mxdiv ; } let arr = [ 100 , 1000 , 10 , 2 ] ; let n = arr . length ; document . write ( maxDivision ( arr , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function coPrimeSet ( n ) { let firstadj , secadj ; if ( n < 4 ) { document . write ( " " ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( i + " " ) ; document . write ( " " + " " ) ; } else { if ( n % 2 == 0 ) { for ( let i = 0 ; i < Math . floor ( n / 2 ) ; i ++ ) { firstadj = 2 * i + 1 ; secadj = 2 * i + 2 ; document . write ( " " + firstadj + " " + secadj + " " + " " ) ; } } else { for ( let i = 0 ; i < Math . floor ( n / 2 ) - 1 ; i ++ ) { firstadj = 2 * i + 1 ; secadj = 2 * i + 2 ; document . write ( " " + firstadj + " " + secadj + " " + " " ) ; } document . write ( " " + ( n - 2 ) + " " + ( n - 1 ) + " " + n + " " + " " ) ; } } } let n = 5 ; coPrimeSet ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function operation ( arr , N ) { let right = 0 , ans = 0 , num = 0 ; for ( let left = 0 ; left < N ; left ++ ) { while ( right < N && num + arr [ right ] == ( num ^ arr [ right ] ) ) { num += arr [ right ] ; right ++ ; } ans += right - left ; if ( left == right ) right ++ ; else num -= arr [ left ] ; } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; document . write ( operation ( arr , N ) ) ;

Index/key variables: left, right
Accumulator variables: ans, left, num, right
Iterator variables: left
Javascript program:
function sieveOfEratosthenes ( N ) { let isPrime = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N + 1 ; i ++ ) { isPrime [ i ] = true ; } isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( isPrime [ i ] == true ) { let j = 2 ; while ( i * j <= N ) { isPrime [ i * j ] = false ; j ++ ; } } } return isPrime ; } function numPairsWithPrimeSum ( arr , n ) { let N = 2 * 1000000 ; let isPrime = sieveOfEratosthenes ( N ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { let sum = arr [ i ] + arr [ j ] ; if ( isPrime [ sum ] ) { count ++ ; } } } return count ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( numPairsWithPrimeSum ( arr , n ) ) ;

Index/key variables: i, j, sum
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let digit = new Uint8Array ( 10 ) ; function digitsPresent ( n ) { let lastDigit ; while ( n != 0 ) { lastDigit = n % 10 ; digit [ lastDigit ] = true ; n = Math . floor ( n / 10 ) ; } } function checkLastDigit ( num ) { let count = 0 ; let lastDigit ; lastDigit = num % 10 ; if ( digit [ lastDigit ] == true ) count ++ ; return count ; } function findCount ( N , K , arr ) { let count = 0 ; for ( let i = 0 ; i < K ; i ++ ) { count = checkLastDigit ( arr [ i ] ) == 1 ? count + 1 : count ; } document . write ( count + " " ) ; } let N = 1731 ; digitsPresent ( N ) ; let K = 5 ; let arr = [ 57 , 6786 , 1111 , 3 , 9812 ] ; findCount ( N , K , arr ) ;

Index/key variables: i, lastDigit
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function find ( K , N ) { N -- ; while ( N -- ) { let curr_term = K ; let min_d = 9 ; let max_d = 0 ; while ( curr_term > 0 ) { let r = curr_term % 10 ; min_d = Math . min ( min_d , r ) ; max_d = Math . max ( max_d , r ) ; curr_term = Math . floor ( curr_term / 10 ) ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } let K = 487 ; let N = 2 ; document . write ( find ( K , N ) + " " ) ;

Accumulator variables: N
Javascript program:
function countSubarrays ( arr , n ) { let mp = new Map ( ) ; let prefixSum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let prefixMin = 0 ; prefixSum [ 0 ] = arr [ 0 ] ; prefixMin = Math . min ( prefixMin , prefixSum [ 0 ] ) ; for ( let i = 1 ; i < n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; prefixMin = Math . min ( prefixMin , prefixSum [ i ] ) ; } let countSubs = 0 ; mp . set ( 0 , 1 ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; prefixSum [ i ] - j * j >= prefixMin ; j ++ ) { if ( mp . has ( prefixSum [ i ] - j * j ) ) countSubs += mp . get ( prefixSum [ i ] - j * j ) ; } if ( mp . has ( prefixSum [ i ] ) ) { mp . set ( prefixSum [ i ] , mp . get ( prefixSum [ i ] ) + 1 ) ; } else { mp . set ( prefixSum [ i ] , 1 ) ; } } return countSubs ; } let arr = [ 2 , 3 , - 5 , 6 , - 7 , 4 ] ; let n = arr . length ; let ans = countSubarrays ( arr , n ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: countSubs, i, j
Iterator variables: i, j
Javascript program:
function positiveProduct ( arr , n ) { let even_count = 0 ; let odd_count = 0 ; let total_count = 0 ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( total_count % 2 == 0 ) { even_count ++ ; } else { odd_count ++ ; } if ( arr [ i ] < 0 ) { total_count ++ ; } if ( total_count % 2 == 0 ) ans += even_count ; else ans += odd_count ; } document . write ( ans ) ; } let A = [ 5 , - 3 , 3 , - 1 , 1 ] ; let size = A . length ; positiveProduct ( A , size ) ;

Index/key variables: i
Accumulator variables: ans, even_count, i, odd_count, total_count
Iterator variables: i
Javascript program:
function findPair ( x ) { let lim = 120 ; for ( let i = - lim ; i <= lim ; i ++ ) for ( let j = - lim ; j <= lim ; j ++ ) if ( Math . pow ( i , 5 ) - Math . pow ( j , 5 ) == x ) { document . write ( i + " " + j ) ; return ; } document . write ( " " ) ; } let X = 33 ; findPair ( X ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getCount ( d , n ) { let no = Math . floor ( n / d ) ; let result = no ; for ( let p = 2 ; p * p <= no ; ++ p ) { if ( no % p == 0 ) { while ( no % p == 0 ) no = Math . floor ( no / p ) ; result = Math . floor ( result - result / p ) ; } } if ( no > 1 ) result = Math . floor ( result - result / no ) ; return result ; } function sumOfGCDofPairs ( n ) { let res = 0 ; for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { let d1 = i ; let d2 = Math . floor ( n / i ) ; res += d1 * getCount ( d1 , n ) ; if ( d1 != d2 ) res += d2 * getCount ( d2 , n ) ; } } return res ; } let n = 12 ; document . write ( sumOfGCDofPairs ( n ) ) ;

Accumulator variables: i, res
Iterator variables: i, p
Javascript program:
function checkIsFibonacci ( arr , n ) { if ( n == 1 n == 2 ) return true ; arr . sort ( ( a , b ) => a - b ) ; for ( i = 2 ; i < n ; i ++ ) { if ( ( arr [ i - 1 ] + arr [ i - 2 ] ) != arr [ i ] ) return false ; } return true ; } var arr = [ 8 , 3 , 5 , 13 ] ; var n = arr . length ; if ( checkIsFibonacci ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lastDigit2PowerN ( n ) { if ( n == 0 ) return 1 ; else if ( n % 4 == 1 ) return 2 ; else if ( n % 4 == 2 ) return 4 ; else if ( n % 4 == 3 ) return 8 ; else } for ( var n = 0 ; n < 20 ; n ++ ) document . write ( lastDigit2PowerN ( n ) + " " ) ;

Accumulator variables: n
Iterator variables: n
Javascript program:
function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function sumSubsequences ( arr , n , k ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } var kLengthSubSequence ; kLengthSubSequence = nCr ( n , k ) ; var ans = sum * ( ( k * kLengthSubSequence ) / n ) ; return ans ; } var arr = [ 7 , 8 , 9 , 2 ] ; var K = 2 ; var n = arr . length ; document . write ( sumSubsequences ( arr , n , K ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findSum ( n , k ) { var val = parseInt ( k / ( n - 1 ) ) * n ; var rem = k % ( n - 1 ) ; if ( rem == 0 ) { val = val - 1 ; } else { val = val + rem ; } var sum = parseInt ( ( val * ( val + 1 ) ) / 2 ) ; var x = parseInt ( k / ( n - 1 ) ) ; var sum_of_multiples = parseInt ( ( x * ( x + 1 ) * n ) / 2 ) ; sum -= sum_of_multiples ; return sum ; } var n = 7 , k = 13 ; document . write ( findSum ( n , k ) )

Accumulator variables: sum
Javascript program:
function getFactorization ( x ) { let count = 0 ; let v = [ ] ; while ( x % 2 == 0 ) { count ++ ; x = Math . floor ( x / 2 ) ; } if ( count != 0 ) v . push ( count ) ; for ( let i = 3 ; i <= Math . floor ( Math . sqrt ( x ) ) ; i += 2 ) { count = 0 ; while ( x % i == 0 ) { count ++ ; x = Math . floor ( x / i ) ; } if ( count != 0 ) v . push ( count ) ; } if ( x > 1 ) { v . push ( 1 ) ; } return v ; } function nonPrimeDivisors ( N ) { let v = getFactorization ( N ) ; let ret = 1 ; for ( let i = 0 ; i < v . length ; i ++ ) ret = ret * ( v [ i ] + 1 ) ; ret = ret - v . length ; return ret ; } let N = 8 ; document . write ( nonPrimeDivisors ( N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
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 checkDigits ( n ) { while ( n != 0 ) { var dig = n % 10 ; if ( dig == 4 && dig == 6 && dig == 7 && dig == 9 ) return false ; n /= 10 ; } return true ; } function isFullfibonacci ( n ) { return ( checkDigits ( n ) && isFibonacci ( n ) ) ; } var n = 13 ; if ( isFullfibonacci ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: n
Javascript program:
function MIN ( n ) { let ans = 11 ; while ( n ) { ans = parseInt ( Math . min ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function MAX ( n ) { let ans = - 1 ; while ( n ) { ans = parseInt ( Math . max ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function Find_value ( n , k ) { k -- ; let x = 0 ; let y = 0 ; while ( k -- ) { x = parseInt ( MIN ( n ) ) ; y = parseInt ( MAX ( n ) ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } document . write ( n ) ; } let N = 487 , D = 5 ; Find_value ( N , D ) ;

Accumulator variables: k, n
Javascript program:
function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function isPrime ( n ) { if ( n <= 1 ) return false ; for ( var i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function countSubsequences ( arr , n , k ) { var countPrime = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( isPrime ( arr [ i ] ) ) countPrime ++ ; } if ( countPrime < k ) return 0 ; return nCr ( countPrime , k ) * Math . pow ( 2 , ( n - countPrime ) ) ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; var K = 3 ; var n = arr . length ; document . write ( countSubsequences ( arr , n , K ) ) ;

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