dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function printSafePrimes ( n ) { let prime = new Array ( n + 1 ) ; for ( let i = 2 ; i <= n ; i ++ ) prime [ i ] = 1 ; prime [ 0 ] = prime [ 1 ] = 0 ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == 1 ) { for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = 0 ; } } for ( let i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] != 0 ) { let temp = ( 2 * i ) + 1 ; if ( temp <= n && prime [ temp ] != 0 ) prime [ temp ] = 2 ; } } for ( let i = 5 ; i <= n ; i ++ ) if ( prime [ i ] == 2 ) document . write ( i + " " ) ; } let n = 20 ; printSafePrimes ( n ) ;

Index/key variables: i, p, temp
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function Divisors ( x ) { var c = 0 ; var v = [ ] ; while ( x % 2 == 0 ) { c ++ ; x /= 2 ; } v . push ( c ) ; c = 0 ; while ( x % 3 == 0 ) { c ++ ; x /= 3 ; } v . push ( c ) ; c = 0 ; while ( x % 7 == 0 ) { c ++ ; x /= 7 ; } v . push ( c ) ; v . push ( x ) ; return v ; } function MinOperations ( a , b ) { var va = Divisors ( a ) ; var vb = Divisors ( b ) ; if ( va [ 3 ] != vb [ 3 ] ) { return - 1 ; } var minOperations = Math . abs ( va [ 0 ] - vb [ 0 ] ) + Math . abs ( va [ 1 ] - vb [ 1 ] ) + Math . abs ( va [ 2 ] - vb [ 2 ] ) ; return minOperations ; } var a = 14 , b = 28 ; document . write ( MinOperations ( a , b ) ) ;

Accumulator variables: c, x
Javascript program:
var n = 1000002 ; var phi = Array ( n + 2 ) . fill ( 0 ) ; var ans = Array ( n + 2 ) . fill ( 0 ) ; function ETF ( ) { for ( i = 1 ; i <= n ; i ++ ) { phi [ i ] = i ; } for ( i = 2 ; i <= n ; i ++ ) { if ( phi [ i ] == i ) { phi [ i ] = i - 1 ; for ( j = 2 * i ; j <= n ; j += i ) { phi [ j ] = ( phi [ j ] * ( i - 1 ) ) / i ; } } } } function LcmSum ( m ) { ETF ( ) ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = i ; j <= n ; j += i ) { ans [ j ] += ( i * phi [ i ] ) ; } } var answer = ans [ m ] ; answer = ( answer + 1 ) * m ; answer = answer / 2 ; return answer ; } var m = 5 ; document . write ( LcmSum ( m ) ) ;

Index/key variables: i, j, m
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function factorial ( n ) { let fact = 1 ; for ( let i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } function ncr ( n , r ) { return Math . floor ( factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ) ; } function countWays ( str ) { let freq = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { freq [ i ] = 0 ; } let nvowels = 0 , nconsonants = 0 ; let vplaces , cways , vways ; for ( let i = 0 ; i < str . length ; i ++ ) ++ freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( i == 0 i == 4 i == 8 i == 14 i == 20 ) nvowels += freq [ i ] ; else nconsonants += freq [ i ] ; } vplaces = nconsonants + 1 ; cways = factorial ( nconsonants ) ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( i != 0 && i != 4 && i != 8 && i != 14 && i != 20 && freq [ i ] > 1 ) { cways = Math . floor ( cways / factorial ( freq [ i ] ) ) ; } } vways = ncr ( vplaces , nvowels ) * factorial ( nvowels ) ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( i == 0 i == 4 i == 8 i == 14 i == 20 && freq [ i ] > 1 ) { vways = Math . floor ( vways / factorial ( freq [ i ] ) ) ; } } return cways * vways ; } let str = " " ; document . write ( countWays ( str ) ) ;

Index/key variables: i
Accumulator variables: i, nconsonants, nvowels
Iterator variables: i
Javascript program:
function setBits ( n ) { let count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } function countPairs ( a , n ) { let count = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let setbits_x = setBits ( a [ i ] ) ; for ( let j = i + 1 ; j < n ; j ++ ) { let setbits_y = setBits ( a [ j ] ) ; let setbits_xor_xy = setBits ( a [ i ] ^ a [ j ] ) ; if ( setbits_x + setbits_y == setbits_xor_xy ) count ++ ; } } return count ; } let a = [ 2 , 3 , 4 , 5 , 6 ] ; let n = a . length ; document . write ( countPairs ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function findPossibleDerivables ( arr , n , D , A , B ) { var gcdAB = gcd ( A , B ) ; var counter = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( ( Math . abs ( arr [ i ] - D ) % gcdAB ) == 0 ) { counter ++ ; } } return counter ; } var arr = [ 1 , 2 , 3 , 4 , 7 , 13 ] ; var n = arr . length ; var D = 5 , A = 4 , B = 2 ; document . write ( findPossibleDerivables ( arr , n , D , A , B ) + " " ) ; var a = [ 1 , 2 , 3 ] ; n = a . length ; D = 6 ; A = 3 ; B = 2 ; document . write ( findPossibleDerivables ( a , n , D , A , B ) ) ;

Index/key variables: i
Accumulator variables: counter, i
Iterator variables: i
Javascript program:
function getElements ( a , arr , n ) { let elements = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { elements [ i ] = 0 ; } elements [ 0 ] = a ; for ( let i = 0 ; i < n ; i ++ ) { elements [ i + 1 ] = arr [ i ] ^ elements [ i ] ; } for ( let i = 0 ; i < n + 1 ; i ++ ) document . write ( elements [ i ] + " " ) ; } let arr = [ 13 , 2 , 6 , 1 ] ; let n = arr . length ; let a = 5 ; getElements ( a , arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxGCD ( N , P ) { let ans = 1 ; let prime_factors = new Map ( ) ; for ( let i = 2 ; i * i <= P ; i ++ ) { while ( P % i == 0 ) { if ( prime_factors . get ( i ) == null ) prime_factors . set ( i , 1 ) ; else prime_factors . set ( i , ( prime_factors . get ( i ) + 1 ) ) ; P = Math . floor ( P / i ) ; } } if ( P != 1 ) prime_factors [ P ] ++ ; console . log ( prime_factors ) for ( let v of prime_factors ) { console . log ( v ) ans *= Math . pow ( v [ 0 ] , Math . floor ( v [ 1 ] / N ) ) ; } return ans ; } let N = 3 , P = 24 ; document . write ( maxGCD ( N , P ) ) ;

Index/key variables: P
Accumulator variables: ans, i
Iterator variables: i, v
Javascript program:
function distinctDigitSum ( n ) { var used = Array ( 10 ) . fill ( false ) ; var sum = 0 ; while ( n > 0 ) { var digit = n % 10 ; if ( ! used [ digit ] ) { used [ digit ] = true ; sum += digit ; } n = parseInt ( n / 10 ) ; } return sum ; } function checkSum ( m , n ) { var sumM = distinctDigitSum ( m ) ; var sumN = distinctDigitSum ( n ) ; if ( sumM == sumN ) return " " ; return " " ; } var m = 2452 , n = 9222 ; document . write ( checkSum ( m , n ) ) ;

Index/key variables: digit
Accumulator variables: sum
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 countPairs ( a , n ) { let count = 0 ; let m = new Map ( ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( isPrime ( a [ i ] ^ a [ j ] ) && ! m . has ( a [ i ] ^ a [ j ] ) ) { m . set ( ( a [ i ] ^ a [ j ] ) , 1 ) ; count ++ ; } } } return count ; } let a = [ 10 , 12 , 23 , 45 , 5 , 6 ] ; let n = a . length ; document . write ( countPairs ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function doubleFactorial ( n ) { var fact = 1 ; for ( var i = 1 ; i <= n ; i = i + 2 ) { fact = fact * i ; } return fact ; } function hermiteNumber ( n ) { if ( n % 2 == 1 ) return 0 ; else { var number = ( Math . pow ( 2 , n / 2 ) ) * doubleFactorial ( n - 1 ) ; if ( ( n / 2 ) % 2 == 1 ) number = number * - 1 ; return number ; } } var n = 6 ; document . write ( hermiteNumber ( n ) ) ;

Iterator variables: i
Javascript program:
function getSum ( n , d ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i % 10 == d ) sum += i ; } return sum ; } let n = 30 ; let d = 3 ; document . write ( getSum ( n , d ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPrime ( N ) { for ( let i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } function getDifference ( N ) { if ( N == 0 ) return 2 ; else if ( N == 1 ) return 1 ; else if ( isPrime ( N ) ) return 0 ; let aboveN = - 1 ; let belowN = - 1 ; let n1 = N + 1 ; while ( true ) { if ( isPrime ( n1 ) ) { aboveN = n1 ; break ; } else n1 ++ ; } n1 = N - 1 ; while ( true ) { if ( isPrime ( n1 ) ) { belowN = n1 ; break ; } else n1 -- ; } let diff1 = aboveN - N ; let diff2 = N - belowN ; return Math . min ( diff1 , diff2 ) ; } let N = 25 ; document . write ( getDifference ( N ) + " " ) ;

Accumulator variables: i, n1
Iterator variables: i
Javascript program:
function check ( arr , x , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let y = Math . sqrt ( arr [ i ] ) ; if ( Math . floor ( y ) == Math . ceil ( y ) ) { sum += arr [ i ] ; } } if ( sum % x == 0 ) return true ; else return false ; } let arr = [ 2 , 3 , 4 , 9 , 10 ] ; let n = arr . length ; let x = 13 ; if ( check ( arr , x , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let MAX = 100000 ; function findLargestDivisor ( n ) { let m = n ; let s = new Set ( ) ; s . add ( 1 ) ; s . add ( n ) ; for ( let i = 2 ; i < Math . floor ( Math . sqrt ( n ) ) + 1 ; i ++ ) { if ( n % i == 0 ) { s . add ( Math . floor ( n / i ) ) ; s . add ( i ) ; while ( m % i == 0 ) m = Math . floor ( m / i ) ; } } if ( m > 1 ) s . add ( m ) ; let l = Array . from ( s ) ; l . sort ( function ( a , b ) { return a - b ; } ) ; l . reverse ( ) ; let vec = [ ] ; for ( let i = 2 ; i <= MAX ; i ++ ) vec . push ( i * i ) ; for ( let d = 0 ; d < l . length ; d ++ ) { let divi = 0 ; for ( let j = 0 ; j < vec . length && vec [ j ] <= l [ d ] ; j ++ ) { if ( l [ d ] % vec [ j ] == 0 ) { divi = 1 ; break ; } } if ( divi == 0 ) return l [ d ] ; } return 0 ; } let n = 12 ; document . write ( findLargestDivisor ( n ) + " " ) ; n = 97 ; document . write ( findLargestDivisor ( n ) + " " ) ;

Index/key variables: d, j
Accumulator variables: d, i, j
Iterator variables: d, i, j
Javascript program:
function NCR ( n , r ) { let numerator = 1 ; let denominator = 1 ; while ( r > 0 ) { numerator *= n ; denominator *= r ; n -- ; r -- ; } return Math . floor ( numerator / denominator ) ; } function findWays ( arr , n ) { let count = new Map ( ) ; if ( n < 4 ) return 0 ; for ( let i = 0 ; i < n ; i ++ ) { count . set ( arr [ i ] , ( count . get ( arr [ i ] ) == null ? 0 : count . get ( arr [ i ] ) + 1 ) ) ; } let remaining_choices = 4 ; let ans = 1 ; for ( let [ key , value ] of count . entries ( ) ) { let number = key ; let frequency = value ; let toSelect = Math . min ( remaining_choices , frequency ) ; ans = ans * NCR ( frequency , toSelect ) ; remaining_choices -= toSelect ; if ( remaining_choices == 0 ) { break ; } } return ans ; } let arr = [ 1 , 2 , 3 , 3 , 3 , 5 ] ; let n = arr . length ; let maxQuadrupleWays = findWays ( arr , n ) ; document . write ( maxQuadrupleWays ) ;

Index/key variables: i
Accumulator variables: denominator, i, n, numerator, r, remaining_choices
Iterator variables: i
Javascript program:
function maxPrimeFactors ( n ) { var num = n ; var maxPrime = - 1 ; while ( n % 2 == 0 ) { maxPrime = 2 ; n = parseInt ( n / 2 ) ; } for ( var i = 3 ; i <= parseInt ( Math . sqrt ( n ) ) ; i += 2 ) { while ( n % i == 0 ) { maxPrime = i ; n = parseInt ( n / i ) ; } } if ( n > 2 ) { maxPrime = n ; } var sum = maxPrime + num ; return sum ; } var n = 19 ; document . write ( maxPrimeFactors ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfDigits ( n ) { var res = 0 ; while ( n > 0 ) { res += n % 10 ; n = parseInt ( n / 10 ) ; } return res ; } function findNumber ( n ) { var i = n - 1 ; while ( i > 0 ) { if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) return i ; i -- ; } return - 1 ; } var n = 824 ; document . write ( findNumber ( n ) ) ;

Accumulator variables: i, res
Javascript program:
function findNth ( N ) { let b = 14 ; for ( let i = 2 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) b = b * 2 ; else b = b - 8 ; } return b ; } N = 6 ; document . write ( findNth ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let N = 4 ; function predictMatrix ( arr , range1a , range1b , range0a , range0b , K , b ) { let c = 0 ; while ( K != 0 ) { K -- ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { c = 0 ; if ( i > 0 && arr [ i - 1 ] [ j ] == 1 ) c ++ ; if ( j > 0 && arr [ i ] [ j - 1 ] == 1 ) c ++ ; if ( i > 0 && j > 0 && arr [ i - 1 ] [ j - 1 ] == 1 ) c ++ ; if ( i < N - 1 && arr [ i + 1 ] [ j ] == 1 ) c ++ ; if ( j < N - 1 && arr [ i ] [ j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j < N - 1 && arr [ i + 1 ] [ j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j > 0 && arr [ i + 1 ] [ j - 1 ] == 1 ) c ++ ; if ( i > 0 && j < N - 1 && arr [ i - 1 ] [ j + 1 ] == 1 ) c ++ ; if ( arr [ i ] [ j ] == 1 ) { if ( c >= range1a && c <= range1b ) b [ i ] [ j ] = 1 ; else b [ i ] [ j ] = 0 ; } if ( arr [ i ] [ j ] == 0 ) { if ( c >= range0a && c <= range0b ) b [ i ] [ j ] = 1 ; else b [ i ] [ j ] = 0 ; } } } for ( let k = 0 ; k < N ; k ++ ) for ( let m = 0 ; m < N ; m ++ ) arr [ k ] [ m ] = b [ k ] [ m ] ; } } let arr = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 1 , 0 , 1 ] ] ; let range1a = 2 , range1b = 2 ; let range0a = 2 , range0b = 3 ; let K = 3 ; let b = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { b [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { b [ i ] [ j ] = 0 ; } } predictMatrix ( arr , range1a , range1b , range0a , range0b , K , b ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( " " ) ; for ( let j = 0 ; j < N ; j ++ ) document . write ( b [ i ] [ j ] + " " ) ; }

Index/key variables: i, j, k, m
Accumulator variables: K, c, i, j, k, m
Iterator variables: i, j, k, m
Javascript program:
function countMoves ( n ) { let ct = 0 ; for ( let i = 1 ; i <= n ; i ++ ) ct += i * ( n - i ) ; ct += n ; return ct ; } let n = 3 ; document . write ( countMoves ( n ) ) ;

Accumulator variables: ct, i
Iterator variables: i
Javascript program:
function getPerfectSquares ( n ) { var perfectSquares = [ ] ; var current = 1 , i = 1 ; while ( current <= n ) { perfectSquares . push ( current ) ; current = Math . pow ( ++ i , 2 ) ; } return perfectSquares ; } function countTriplets ( n ) { var perfectSquares = getPerfectSquares ( Math . pow ( n , 2 ) ) ; var count = 0 ; for ( var a = 1 ; a <= n ; a ++ ) { var aSquare = Math . pow ( a , 2 ) ; for ( var i = 0 ; i < perfectSquares . length ; i ++ ) { var cSquare = perfectSquares [ i ] ; var bSquare = Math . abs ( cSquare - aSquare ) ; var b = Math . sqrt ( bSquare ) ; var c = Math . sqrt ( cSquare ) ; if ( c < a || ! perfectSquares . includes ( bSquare ) ) continue ; if ( ( b >= a ) && ( b <= c ) && ( aSquare + bSquare == cSquare ) ) count ++ ; } } return count ; } var n = 10 ; document . write ( countTriplets ( n ) ) ;

Index/key variables: i
Accumulator variables: a, count, i
Iterator variables: a, i
Javascript program:
let N = 3 ; function calcDeterminant ( arr ) { let determinant = 0 ; for ( let i = 0 ; i < N ; i ++ ) { determinant += Math . pow ( arr [ i ] , 3 ) ; } determinant -= 3 * arr [ 0 ] * arr [ 1 ] * arr [ 2 ] ; return determinant ; } let arr = [ 4 , 5 , 3 ] ; document . write ( calcDeterminant ( arr ) ) ;

Index/key variables: i
Accumulator variables: determinant, i
Iterator variables: i
Javascript program:
function MinSteps ( SourceX , SourceY , DestX , DestY ) { document . write ( Math . max ( Math . abs ( SourceX - DestX ) , Math . abs ( SourceY - DestY ) ) + " " ) ; while ( ( SourceX != DestX ) || ( SourceY != DestY ) ) { if ( SourceX < DestX ) { document . write ( ' ' ) ; SourceX ++ ; } if ( SourceX > DestX ) { document . write ( ' ' ) ; SourceX -- ; } if ( SourceY > DestY ) { document . write ( ' ' ) ; SourceY -- ; } if ( SourceY < DestY ) { document . write ( ' ' ) ; SourceY ++ ; } document . write ( " " ) ; } } let sourceX = 4 , sourceY = 4 ; let destinationX = 7 , destinationY = 0 ; MinSteps ( sourceX , sourceY , destinationX , destinationY ) ;

Accumulator variables: SourceX, SourceY
Javascript program:
function findEle ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] == sum - arr [ i ] ) return arr [ i ] ; return - 1 ; } var arr = [ 1 , 2 , 3 , 6 ] ; var n = arr . length ; document . write ( findEle ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function divisibleBy3 ( number ) { let sumOfDigit = 0 ; for ( let i = 0 ; i < number . length ; i ++ ) sumOfDigit += number [ i ] - ' ' ; if ( sumOfDigit % 3 == 0 ) return true ; return false ; } function divisibleBy25 ( number ) { if ( number . length < 2 ) return false ; let length = number . length ; let lastTwo = ( number [ length - 2 ] - ' ' ) * 10 + ( number [ length - 1 ] - ' ' ) ; if ( lastTwo % 25 == 0 ) return true ; return false ; } function divisibleBy75 ( number ) { if ( divisibleBy3 ( number ) && divisibleBy25 ( number ) ) return true ; return false ; } let number = " " ; let divisible = divisibleBy75 ( number ) ; if ( divisible ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sumOfDigit
Iterator variables: i
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function sumAP ( n , d ) { n = parseInt ( n / d ) ; return ( n ) * ( 1 + n ) * d / 2 ; } function sumMultiples ( A , B , n ) { n -- ; common = parseInt ( ( A * B ) / __gcd ( A , B ) ) ; return sumAP ( n , A ) + sumAP ( n , B ) - sumAP ( n , common ) ; } let n = 100 ; let A = 5 ; let B = 10 ; document . write ( " " + sumMultiples ( A , B , n ) ) ;

Accumulator variables: n
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( var i = 2 ; i <= parseInt ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function isPossible ( N ) { if ( isPrime ( N ) && isPrime ( N - 2 ) ) return true ; else return false ; } var n = 13 ; if ( isPossible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function totalPairs ( arr1 , arr2 , K , n , m ) { var s = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { if ( arr1 [ i ] > arr2 [ j ] ) { if ( arr1 [ i ] % arr2 [ j ] == K ) s . add ( [ arr1 [ i ] , arr2 [ j ] ] ) ; } else { if ( arr2 [ j ] % arr1 [ i ] == K ) s . add ( [ arr2 [ j ] , arr1 [ i ] ] ) ; } } } return s . size ; } var arr1 = [ 8 , 3 , 7 , 50 ] ; var arr2 = [ 5 , 1 , 10 , 4 ] ; var K = 3 ; var n = arr1 . length ; var m = arr2 . length ; document . write ( totalPairs ( arr1 , arr2 , K , n , m ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function contiguousPerfectSquare ( arr , n ) { var a ; var b ; var current_length = 0 ; var max_length = 0 ; for ( var i = 0 ; i < n ; i ++ ) { b = ( Math . sqrt ( arr [ i ] ) ) ; a = parseInt ( b ) ; if ( a == b ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } var arr = [ 9 , 75 , 4 , 64 , 121 , 25 ] ; var n = arr . length ; document . write ( contiguousPerfectSquare ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: current_length, i
Iterator variables: i
Javascript program:
function countPairs ( n ) { let count = 0 ; for ( let x = 1 ; x < n ; x ++ ) { for ( let y = x + 1 ; y <= n ; y ++ ) { if ( ( y * x ) % ( y + x ) == 0 ) count ++ ; } } return count ; } let n = 15 ; document . write ( countPairs ( n ) ) ;

Accumulator variables: count, x, y
Iterator variables: x, y
Javascript program:
function getIndex ( a , n ) { if ( n == 1 ) return 0 ; let ptrL = 0 , ptrR = n - 1 , sumL = a [ 0 ] , sumR = a [ n - 1 ] ; while ( ptrR - ptrL > 1 ) { if ( sumL < sumR ) { ptrL ++ ; sumL += a [ ptrL ] ; } else if ( sumL > sumR ) { ptrR -- ; sumR += a [ ptrR ] ; } else { break ; } } return ptrL ; } let a = [ 2 , 7 , 9 , 8 , 7 ] ; let n = a . length ; document . write ( getIndex ( a , n ) ) ;

Index/key variables: ptrL, ptrR
Accumulator variables: ptrL, ptrR, sumL, sumR
Javascript program:
function getPosition ( a , n , m ) { for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] / m + ( a [ i ] % m ) ) ; } let ans = - 1 , max = - 1 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( max < a [ i ] ) { max = a [ i ] ; ans = i ; } } return ans + 1 ; } let a = [ 2 , 5 , 4 ] ; let n = a . length ; let m = 2 ; document . write ( getPosition ( a , n , m ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calcFunction ( n , r ) { var finalDenominator = 1 ; var mx = Math . max ( r , n - r ) ; for ( var i = mx + 1 ; i <= n ; i ++ ) { var denominator = Math . pow ( i , i ) ; var numerator = Math . pow ( i - mx , i - mx ) ; finalDenominator = ( finalDenominator * denominator ) / numerator ; } return finalDenominator ; } var n = 6 , r = 2 ; document . write ( " " + calcFunction ( n , r ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isExists ( a , n ) { let freq = new Map ( ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { freq . set ( a [ i ] , freq . get ( a [ i ] ) == null ? 0 : freq . get ( a [ i ] ) + 1 ) ; sum += a [ i ] ; } if ( sum % 2 == 0 ) { if ( freq . get ( sum / 2 ) != null ) return true ; } return false ; } let a = [ 5 , 1 , 2 , 2 ] ; let n = a . length ; if ( isExists ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let st = new Set ( ) ; function generateNumbers ( n , num , a , b ) { if ( num > 0 && num < n ) st . add ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } function printNumbers ( n ) { for ( let i = 0 ; i <= 9 ; i ++ ) for ( let j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; document . write ( " " ) ; document . write ( Array . from ( st ) . sort ( function ( a , b ) { return a - b ; } ) . join ( " " ) ) ; st . clear ( ) ; } let n = 12 ; printNumbers ( n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findPrime ( MAX ) { let pm = new Array ( MAX + 1 ) ; pm . fill ( true ) ; pm [ 0 ] = pm [ 1 ] = false ; for ( let i = 2 ; i <= MAX ; i ++ ) if ( pm [ i ] ) for ( let j = 2 * i ; j <= MAX ; j += i ) pm [ j ] = false ; let prime = new Array ( ) ; for ( let i = 0 ; i <= MAX ; i ++ ) if ( pm [ i ] ) prime . push ( i ) ; return prime ; } function findSmallest ( arr , n ) { let MAX = arr . sort ( ( A , B ) => A - B ) . reverse ( ) [ 0 ] ; let prime = findPrime ( MAX ) ; let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; let ans = - 1 ; for ( let i = 0 ; i < prime . length ; i ++ ) { if ( ! s . has ( prime [ i ] ) ) { ans = prime [ i ] ; break ; } } return ans ; } let arr = [ 3 , 0 , 1 , 2 , 7 ] ; let n = arr . length ; if ( findSmallest ( arr , n ) == - 1 ) document . write ( " " ) ; else document . write ( findSmallest ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findNum ( div , rem , N ) { var num = rem [ N - 1 ] ; for ( var i = N - 2 ; i >= 0 ; i -- ) { num = num * div [ i ] + rem [ i ] ; } return num ; } var div = [ 8 , 3 ] ; var rem = [ 2 , 2 ] ; var N = div . length ; document . write ( findNum ( div , rem , N ) ) ;

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