dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function getPerfectcubes ( n ) { let perfectcubes = [ ] ; let current = 1 ; let i = 1 ; while ( current <= n ) { perfectcubes . push ( current ) ; i += 1 ; current = parseInt ( Math . pow ( i , 3 ) ) ; } return perfectcubes ; } function maxPairSum ( arr , n ) { let max = 0 ; let secondMax = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { max = arr [ 0 ] ; secondMax = arr [ 1 ] ; } else { max = arr [ 1 ] ; secondMax = arr [ 0 ] ; } for ( let i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { secondMax = max ; max = arr [ i ] ; } else if ( arr [ i ] > secondMax ) secondMax = arr [ i ] ; } return ( max + secondMax ) ; } function countPairsWith ( n , perfectcubes , nums ) { let count = 0 ; let len = perfectcubes . length ; for ( let i = 0 ; i < len ; i ++ ) { let temp = perfectcubes [ i ] - n ; if ( temp > n ) { for ( let j = 0 ; j < nums . length ; j ++ ) { if ( nums [ j ] == temp ) count += 1 ; } } } return count ; } function countPairs ( arr , n ) { let max = maxPairSum ( arr , n ) ; let perfectcubes = getPerfectcubes ( max ) ; let nums = [ ] ; for ( let i = 0 ; i < n ; i ++ ) nums . push ( arr [ i ] ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { count += countPairsWith ( arr [ i ] , perfectcubes , nums ) ; } return count ; } let arr = [ 2 , 6 , 18 , 9 , 999 , 1 ] ; let n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function countCubes ( a , b ) { for ( let i = a ; i <= b ; i ++ ) for ( let j = 1 ; j * j * j <= i ; j ++ ) if ( j * j * j == i ) cnt ++ ; return cnt ; } let a = 7 , b = 30 ; document . write ( " " + countCubes ( a , b ) ) ;

Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function isArmstrong ( x , n ) { let sum1 = 0 ; let temp = x ; while ( temp > 0 ) { let digit = temp % 10 ; sum1 += Math . pow ( digit , n ) ; temp = parseInt ( temp / 10 , 10 ) ; } return ( sum1 == x ) ; } function CalculateXORandOR ( n ) { let CalculateXOR = 0 ; let CalculateOR = 0 ; let start = Math . pow ( 10 , n - 1 ) ; let end = ( Math . pow ( 10 , n ) ) - 1 ; for ( let i = start ; i < end + 1 ; i ++ ) { if ( isArmstrong ( i , n ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } document . write ( " " + CalculateXOR + " " ) ; document . write ( " " + CalculateOR + " " ) ; } let n = 4 ; CalculateXORandOR ( n ) ;

Accumulator variables: i, sum1
Iterator variables: i
Javascript program:
function perfectCube ( N ) { let cube ; for ( let i = 0 ; i <= N ; i ++ ) { cube = i * i * i ; if ( cube === N ) { document . write ( " " ) ; return ; } else if ( cube > N ) { document . write ( " " ) ; return ; } } } let N = 216 ; perfectCube ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( arr , N ) { let even = 0 ; let odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) { odd ++ ; } else { even ++ ; } } if ( even == N odd == N ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 1 , 1 , 3 ] ; let N = arr . length ; check ( arr , N ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function findMinNumber ( n ) { var count = 0 , ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 3 != 0 ) ans *= Math . pow ( 2 , ( count % 3 ) ) ; for ( var i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 3 != 0 ) ans *= Math . pow ( i , ( count % 3 ) ) ; } if ( n > 2 ) ans *= n ; return ans ; } var n = 128 ; document . write ( findMinNumber ( n ) ) ;

Accumulator variables: ans, count, i, n
Iterator variables: i
Javascript program:
function countSteps ( n ) { let steps = 0 ; while ( n ) { let largest = Math . floor ( Math . cbrt ( n ) ) ; n -= ( largest * largest * largest ) ; steps ++ ; } return steps ; } let n = 150 ; document . write ( countSteps ( n ) ) ;

Accumulator variables: n, steps
Javascript program:
function product ( N ) { let ans = 1 ; let val = Math . pow ( 2 , N - 1 ) ; for ( let i = 1 ; i <= N ; i ++ ) { ans *= Math . pow ( i , val ) ; } return ans ; } let N = 2 ; document . write ( product ( N ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function remainingArea ( N , M , K ) { while ( K -- && N && M ) { if ( N > M ) N = N - M ; else M = M - N ; } if ( N > 0 && M > 0 ) return N * M ; else return 0 ; } var N = 5 , M = 3 , K = 2 ; document . write ( remainingArea ( N , M , K ) ) ;

Accumulator variables: K
Javascript program:
function isPossible ( a , n ) { let sum = 0 , maxS = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; maxS = Math . max ( a [ i ] , maxS ) ; } if ( ( sum - maxS ) > maxS ) return true ; return false ; } let a = [ 2 , 3 , 4 ] ; let n = a . length ; if ( isPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isSlopeGood ( slope , arr , n ) { var setOfLines = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) setOfLines . add ( arr [ i ] - slope * ( i ) ) ; return setOfLines . size == 2 ; } function checkForParallel ( arr , n ) { var slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; var slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; var slope3 = isSlopeGood ( parseInt ( ( arr [ 2 ] - arr [ 0 ] ) / 2 ) , arr , n ) ; if ( slope1 slope2 slope3 ) { return 1 ; } return 0 ; } var arr = [ 1 , 6 , 3 , 8 , 5 ] ; var n = arr . length ; document . write ( checkForParallel ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findFourthVertex ( n , m , s ) { var row = new Map ( ) , col = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < m ; j ++ ) if ( s [ i ] [ j ] == ' ' ) { if ( row . has ( i ) ) row . set ( i , row . get ( i ) + 1 ) else row . set ( i , 1 ) if ( col . has ( j ) ) col . set ( j , col . get ( j ) + 1 ) else col . set ( j , 1 ) } var x , y ; row . forEach ( ( value , key ) => { if ( value == 1 ) x = key ; } ) ; col . forEach ( ( value , key ) => { if ( value == 1 ) y = key ; } ) ; return [ x + 1 , y + 1 ] ; } var s = [ " " , " " , " " ] ; var n = s . length ; var m = s [ 0 ] . length ; var rs = findFourthVertex ( n , m , s ) ; document . write ( rs [ 0 ] + " " + rs [ 1 ] ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var MAX = 50 function solveQuery ( n , q , qi , qj ) { var arr = Array ( MAX ) ; for ( var i = 0 ; i <= n ; i ++ ) arr [ i ] = 0 ; for ( var k = 0 ; k < q ; k ++ ) { var flag = 0 ; if ( qj [ k ] < qi [ k ] ) { var temp = qi [ k ] ; qi [ k ] = qj [ k ] ; qj [ k ] = temp ; } if ( arr [ qi [ k ] ] != 0 arr [ qj [ k ] ] != 0 ) flag = 1 ; else if ( qi [ k ] == qj [ k ] ) flag = 1 ; else { for ( var i = 1 ; i < qi [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] < qj [ k ] && qi [ k ] < arr [ i ] ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( var i = qi [ k ] + 1 ; i < qj [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] > qj [ k ] ) { flag = 1 ; break ; } } } } if ( flag == 0 ) { document . write ( " " ) ; arr [ qi [ k ] ] = qj [ k ] ; arr [ qj [ k ] ] = qi [ k ] ; } else document . write ( " " ) ; } } var n = 10 ; var q = 7 ; var qi = [ 1 , 2 , 2 , 2 , 9 , 10 , 8 ] ; var qj = [ 5 , 7 , 3 , 4 , 9 , 9 , 6 ] ; solveQuery ( n , q , qi , qj ) ;

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
{ constructor ( ) { this . x = 0 ; this . y = 0 ; } } function orientation ( p , q , r ) { let val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y ) ; if ( val == 0 ) return 0 ; return ( val > 0 ) ? 1 : 2 ; } function doIntersect ( p1 , q1 , p2 , q2 ) { let o1 = orientation ( p1 , q1 , p2 ) ; let o2 = orientation ( p1 , q1 , q2 ) ; let o3 = orientation ( p2 , q2 , p1 ) ; let o4 = orientation ( p2 , q2 , q1 ) ; if ( o1 != o2 && o3 != o4 ) return true ; return false ; } function similar ( p1 , p2 ) { if ( p1 . x == p2 . x && p1 . y == p2 . y ) return false ; return true ; } function collinear ( p1 , p2 , p3 ) { let x1 = p1 . x , y1 = p1 . y ; let x2 = p2 . x , y2 = p2 . y ; let x3 = p3 . x , y3 = p3 . y ; if ( ( y3 - y2 ) * ( x2 - x1 ) == ( y2 - y1 ) * ( x3 - x2 ) ) return false ; else return true ; } function no_of_quads ( p1 , p2 , p3 , p4 ) { let same = true ; same = same & similar ( p1 , p2 ) ; same = same & similar ( p1 , p3 ) ; same = same & similar ( p1 , p4 ) ; same = same & similar ( p2 , p3 ) ; same = same & similar ( p2 , p4 ) ; same = same & similar ( p3 , p4 ) ; if ( same == false ) return 0 ; let coll = true ; coll = coll & collinear ( p1 , p2 , p3 ) ; coll = coll & collinear ( p1 , p2 , p4 ) ; coll = coll & collinear ( p1 , p3 , p4 ) ; coll = coll & collinear ( p2 , p3 , p4 ) ; if ( coll == false ) return 0 ; let check = 0 ; if ( doIntersect ( p1 , p2 , p3 , p4 ) ) check = 1 ; if ( doIntersect ( p1 , p3 , p2 , p4 ) ) check = 1 ; if ( doIntersect ( p1 , p2 , p4 , p3 ) ) check = 1 ; if ( check == 0 ) return 3 ; return 1 ; } let p1 , p2 , p3 , p4 ; p1 = new Point ( ) ; p2 = new Point ( ) ; p3 = new Point ( ) ; p4 = new Point ( ) ; p1 . x = 0 ; p1 . y = 9 ; p2 . x = - 1 ; p2 . y = 0 ; p3 . x = 5 ; p3 . y = - 1 ; p4 . x = 5 ; p4 . y = 9 ; document . write ( no_of_quads ( p1 , p2 , p3 , p4 ) + " " ) ; p1 . x = 0 ; p1 . y = 9 ; p2 . x = - 1 ; p2 . y = 0 ; p3 . x = 5 ; p3 . y = - 1 ; p4 . x = 0 ; p4 . y = 3 ; document . write ( no_of_quads ( p1 , p2 , p3 , p4 ) + " " ) ; p1 . x = 0 ; p1 . y = 9 ; p2 . x = 0 ; p2 . y = 10 ; p3 . x = 0 ; p3 . y = 11 ; p4 . x = 0 ; p4 . y = 12 ; document . write ( no_of_quads ( p1 , p2 , p3 , p4 ) + " " ) ; p1 . x = 0 ; p1 . y = 9 ; p2 . x = 0 ; p2 . y = 9 ; p3 . x = 5 ; p3 . y = - 1 ; p4 . x = 0 ; p4 . y = 3 ; document . write ( no_of_quads ( p1 , p2 , p3 , p4 ) + " " ) ;

Boolean variables: coll, same
Javascript program:
function pentagon_pyramidal ( n ) { var sum = 0 ; for ( i = 1 ; i <= n ; i ++ ) { var p = ( 3 * i * i - i ) / 2 ; sum = sum + p ; } return sum ; } var n = 4 ; document . write ( pentagon_pyramidal ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( a , b ) { var res = 1 ; for ( var i = 1 ; i <= ( a + b ) ; i ++ ) res = res * i ; for ( var i = 1 ; i <= a ; i ++ ) res = res / i ; for ( var i = 1 ; i <= b ; i ++ ) res = res / i ; return res ; } function Ksmallest ( x , y , k ) { if ( x == 0 && y == 0 ) return ; else if ( x == 0 ) { y -- ; document . write ( " " ) ; Ksmallest ( x , y , k ) ; } else if ( y == 0 ) { x -- ; document . write ( " " ) ; Ksmallest ( x , y , k ) ; } else { if ( factorial ( x - 1 , y ) > k ) { document . write ( " " ) ; Ksmallest ( x - 1 , y , k ) ; } else { document . write ( " " ) ; Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) ; } } } var x = 2 , y = 2 , k = 2 ; Ksmallest ( x , y , k ) ;

Accumulator variables: i, x, y
Iterator variables: i
Javascript program:
function isBetween ( a , b , c ) { return ( Math . min ( a , b ) <= c && c <= Math . max ( a , b ) ) ; } function canJoin ( x , y , i , j , k ) { return ( x [ k ] == x [ i ] x [ k ] == x [ j ] ) && isBetween ( y [ i ] , y [ j ] , y [ k ] ) || ( y [ k ] == y [ i ] y [ k ] == y [ j ] ) && isBetween ( x [ i ] , x [ j ] , x [ k ] ) ; } function countLineSegments ( x , y ) { if ( ( x [ 0 ] == x [ 1 ] && x [ 1 ] == x [ 2 ] ) || ( y [ 0 ] == y [ 1 ] && y [ 1 ] == y [ 2 ] ) ) return 1 ; else if ( canJoin ( x , y , 0 , 1 , 2 ) || canJoin ( x , y , 0 , 2 , 1 ) || canJoin ( x , y , 1 , 2 , 0 ) ) return 2 ; else return 3 ; } let x = [ ] , y = [ ] ; x [ 0 ] = - 1 ; y [ 0 ] = - 1 ; x [ 1 ] = - 1 ; y [ 1 ] = 3 ; x [ 2 ] = 4 ; y [ 2 ] = 3 ; document . write ( countLineSegments ( x , y ) ) ;

Index/key variables: i, j, k
Javascript program:
class point { constructor ( ) { this . x = 0 ; this . y = 0 ; } } let RIGHT = 1 , LEFT = - 1 , ZERO = 0 ; function directionOfPoint ( A , B , P ) { B . x -= A . x ; B . y -= A . y ; P . x -= A . x ; P . y -= A . y ; let cross_product = B . x * P . y - B . y * P . x ; if ( cross_product > 0 ) return RIGHT ; if ( cross_product < 0 ) return LEFT ; return ZERO ; } let A = new point ( ) , B = new point ( ) , P = new point ( ) ; A . x = - 30 ; B . x = 29 ; P . x = 15 ; let direction = directionOfPoint ( A , B , P ) ; if ( direction == 1 ) document . write ( " " ) ; else if ( direction == - 1 ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: x, y
Class/struct names: point
Javascript program:
function minRadius ( k , x , y , n ) { let dis = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < n ; i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ; dis . sort ( ) ; return dis [ k - 1 ] ; } let k = 3 ; let x = [ 1 , - 1 , 1 ] ; let y = [ 1 , - 1 , - 1 ] ; let n = x . length ; document . write ( minRadius ( k , x , y , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minPerimeter ( n ) { let l = Math . sqrt ( n ) ; let sq = l * l ; if ( sq == n ) return l * 4 ; else { let row = n / l ; let perimeter = 2 * ( l + row ) ; if ( n % l != 0 ) perimeter += 2 ; return perimeter ; } } let n = 10 ; document . write ( Math . floor ( minPerimeter ( n ) ) )

Accumulator variables: perimeter
Javascript program:
function findTriangle ( a , n ) { let b = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { b [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) b [ i ] = a [ i ] * a [ i ] ; a . sort ( function ( i , j ) { return i - j ; } ) ; b . sort ( function ( i , j ) { return i - j ; } ) ; let x = 0 , y = 0 , z = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let p = i + 1 ; let q = i + 1 ; for ( let j = i + 1 ; j < n ; j ++ ) { while ( p < n - 1 && b [ i ] + b [ j ] >= b [ p + 1 ] ) p ++ ; q = Math . max ( q , p ) ; while ( q < n - 1 && a [ i ] + a [ j ] > a [ q + 1 ] ) q ++ ; if ( b [ i ] + b [ j ] == b [ p ] ) { x += Math . max ( p - j - 1 , 0 ) ; y ++ ; z += q - p ; } else { x += Math . max ( p - j , 0 ) ; z += q - p ; } } } document . write ( " " + x + " " ) ; document . write ( " " + y + " " ) ; document . write ( " " + z + " " ) ; } let arr = [ 2 , 3 , 9 , 10 , 12 , 15 ] ; let n = arr . length ; findTriangle ( arr , n ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, p, q, x, y, z
Iterator variables: i, j
Javascript program:
class point { constructor ( x , y ) { this . x = x ; this . y = y ; } } function square ( x ) { return x * x ; } let a , b , c ; function order ( ) { let copy = new Array ( 3 ) ; copy [ 0 ] = a ; copy [ 1 ] = b ; copy [ 2 ] = c ; ( copy ) . sort ( function ( a , b ) { return a - b ; } ) ; a = copy [ 0 ] ; b = copy [ 1 ] ; c = copy [ 2 ] ; } function euclidDistSquare ( p1 , p2 ) { return square ( p1 . x - p2 . x ) + square ( p1 . y - p2 . y ) ; } function getSideClassification ( a , b , c ) { if ( a == b && b == c ) return " " ; else if ( a == b b == c ) return " " ; else return " " ; } function getAngleClassification ( a , b , c ) { if ( a + b > c ) return " " ; else if ( a + b == c ) return " " ; else return " " ; } function classifyTriangle ( p1 , p2 , p3 ) { a = euclidDistSquare ( p1 , p2 ) ; b = euclidDistSquare ( p1 , p3 ) ; c = euclidDistSquare ( p2 , p3 ) ; order ( ) ; document . write ( " " + getAngleClassification ( a , b , c ) + " " + getSideClassification ( a , b , c ) + " " ) ; } let p1 , p2 , p3 ; p1 = new point ( 3 , 0 ) ; p2 = new point ( 0 , 4 ) ; p3 = new point ( 4 , 7 ) ; classifyTriangle ( p1 , p2 , p3 ) ; p1 = new point ( 0 , 0 ) ; p2 = new point ( 1 , 1 ) ; p3 = new point ( 1 , 2 ) ; classifyTriangle ( p1 , p2 , p3 ) ;

Class/struct names: point
Javascript program:
function polygonArea ( X , Y , n ) { let area = 0.0 ; let j = n - 1 ; for ( let i = 0 ; i < n ; i ++ ) { area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ; j = i ; } return Math . abs ( area / 2.0 ) ; } let X = [ 0 , 2 , 4 ] ; let Y = [ 1 , 3 , 7 ] ; let n = 3 ; document . write ( polygonArea ( X , Y , n ) ) ;

Index/key variables: i, j
Accumulator variables: area, i
Iterator variables: i
Javascript program:
function findDifferenceArray ( arr , N ) { let S1 = new Set ( ) ; let S2 = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { S1 . add ( arr [ j ] ) ; } for ( let j = i + 1 ; j < N ; j ++ ) { S2 . add ( arr [ j ] ) ; } document . write ( Math . abs ( S1 . size - S2 . size ) + ' ' ) ; S1 . clear ( ) ; S2 . clear ( ) ; } } let arr = [ 7 , 7 , 3 , 2 , 3 ] ; let N = arr . length ; findDifferenceArray ( arr , N ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumSubarraySum ( arr ) { let N = arr . length ; let memo = new Map ( ) ; let res = - 99999999 ; let currsum = 0 , currval = 0 ; for ( let i = 0 ; i < N ; ++ i ) { currval = arr [ i ] ; currsum = currsum + currval ; if ( memo . has ( currval ) ) { if ( currval > 0 ) res = Math . max ( res , currsum - memo . get ( currval ) + currval ) ; else res = Math . max ( res , currsum - memo . get ( currval ) + 2 * currval ) ; } else memo . set ( currval , currsum ) ; if ( currval < 0 ) currsum = currsum - currval ; } return res ; } let arr = [ - 1 , - 3 , 4 , 0 , - 1 , - 2 ] ; document . write ( maximumSubarraySum ( arr ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { let res = 1 , i ; for ( i = 2 ; i <= n ; i ++ ) { res *= i ; } return res ; } function countPermutations ( ar , n ) { let mp = new Map ( ) ; let ans = 1 , cnt = n ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( ar [ i ] ) ) { mp . set ( ar [ i ] , mp . get ( ar [ i ] ) + 1 ) } else { mp . set ( ar [ i ] , 1 ) } } for ( let i = 0 ; i < n ; i ++ ) { if ( ! mp . has ( i ) ) { break ; } ans = ( ans * mp . get ( i ) ) ; cnt -- ; } ans = ans * factorial ( cnt ) ; return ans ; } let arr = [ 1 , 0 , 1 ] ; let N = arr . length document . write ( countPermutations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, res
Iterator variables: i
Javascript program:
function minimumAdditionOperation ( N ) { let count = 0 ; while ( N ) { if ( N & ( 1 == 1 ) ) { count ++ ; } N = N >> 1 ; } return count ; } let N = 6 ; document . write ( minimumAdditionOperation ( N ) ) ;

Accumulator variables: count
Javascript program:
const maxn = 100000 ; let prime = new Array ( maxn ) . fill ( 0 ) ; function semiPrimes ( N ) { for ( let p = 2 ; p <= maxn ; p ++ ) { if ( prime [ p ] == 0 ) { for ( let i = 2 * p ; i <= maxn ; i += p ) prime [ i ] ++ ; } } let sPrimes = [ ] ; for ( let p = 2 ; p <= N ; p ++ ) if ( prime [ p ] == 2 ) sPrimes . push ( p ) ; return sPrimes ; } function countPairs ( semiPrimes ) { let cnt = 0 ; for ( let i = 0 ; i < semiPrimes . length ; i ++ ) { for ( let j = i + 1 ; j < semiPrimes . length ; j ++ ) { if ( prime [ semiPrimes [ i ] + semiPrimes [ j ] ] == 0 ) { cnt ++ ; } } } return cnt ; } let N = 100 ; document . write ( countPairs ( semiPrimes ( N ) ) ) ;

Index/key variables: i, j, p
Accumulator variables: cnt, i, j, p
Iterator variables: i, j, p
Javascript program:
function minimumOperations ( arr , N ) { let mini = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < N ; i ++ ) { let count = 0 ; while ( arr [ i ] % 2 == 0 ) { arr [ i ] = Math . floor ( arr [ i ] / 2 ) ; count ++ ; } if ( mini > count ) { mini = count ; } } return mini ; } let arr = [ 4 , 6 ] ; let N = arr . length ; document . write ( minimumOperations ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countTriplets ( N ) { let cnt = 0 ; for ( let A = 1 ; A <= N ; ++ A ) { for ( let B = 1 ; B <= N / A ; ++ B ) { cnt += N / ( A * B ) ; } } return cnt ; } let N = 2 ; document . write ( countTriplets ( N ) ) ;

Accumulator variables: cnt
Iterator variables: A, B
Javascript program:
const maxn = 100001 ; let gpf = new Array ( maxn ) ; function modifiedSieve ( ) { gpf . fill ( 0 ) ; gpf [ 0 ] = 0 ; gpf [ 1 ] = 1 ; for ( let i = 2 ; i < maxn ; i ++ ) { if ( gpf [ i ] > 0 ) continue ; for ( let j = i ; j < maxn ; j += i ) { gpf [ j ] = Math . max ( i , gpf [ j ] ) ; } } } function greatestValidInt ( N ) { modifiedSieve ( ) ; for ( let i = N ; i > 0 ; i -- ) { if ( gpf [ i ] > Math . sqrt ( i ) ) { return i ; } } return - 1 ; } let N = 25 ; document . write ( greatestValidInt ( N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const numberOfPasses = ( arr , N ) => { for ( let i = 0 ; i < N ; ++ i ) { -- arr [ i ] ; } for ( let i = 0 ; i < N ; ++ i ) { let cnt = 0 ; let k = i ; do { ++ cnt ; k = arr [ k ] ; } while ( k != i ) ; document . write ( ` ${ cnt } ` ) ; } } let arr = [ 4 , 6 , 2 , 1 , 5 , 3 ] ; let N = arr . length ; numberOfPasses ( arr , N ) ;

Index/key variables: i, k
Iterator variables: i
Javascript program:
function subfactorial ( N ) { let res = 0 , fact = 1 ; let count = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { fact = fact * i ; if ( count % 2 == 0 ) res = res - 1 / fact ; else res = res + 1 / fact ; count ++ ; } return fact * ( 1 + res ) ; } let N = 4 ; document . write ( subfactorial ( N ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minOperations ( A , B , N ) { let cnt = 0 ; let i = 0 ; while ( i < N ) { let j = 0 ; while ( j < N && i < N ) { if ( B [ i ] == A [ j ] ) { i ++ ; } j ++ ; } cnt ++ ; } return cnt ; } let A = [ 2 , 4 , 6 , 1 , 5 , 3 ] ; let B = [ 6 , 5 , 4 , 2 , 3 , 1 ] ; let N = A . length ; document . write ( minOperations ( A , B , N ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Javascript program:
function countPairs ( N ) { let res = 0 ; for ( let q = 1 ; q * q <= N ; q ++ ) { let maxP = Math . min ( 2 * N - q , N / q ) ; if ( maxP < q ) continue ; let cnt = maxP - q + 1 ; res += Math . floor ( cnt / 2 + ( cnt & 1 ) ) ; } return res ; } let N = 3 ; document . write ( countPairs ( N ) ) ;

Accumulator variables: q, res
Iterator variables: q
Javascript program:
function maximizeSubset ( N , arr , M , x = 0 ) { if ( x == M ) { return 0 ; } let ans = 0 ; for ( let i = x ; i < M ; i ++ ) { if ( N % arr [ i ] == 0 ) { ans = Math . max ( ans , maximizeSubset ( Math . floor ( N / arr [ i ] ) , arr , M , x + 1 ) + 1 ) ; } } return ans ; } let N = 64 ; let arr = [ 1 , 2 , 4 , 8 , 16 , 32 ] ; let M = arr . length ; document . write ( maximizeSubset ( N , arr , M ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function setSumtoZero ( arr , N ) { let A = new Array ( N ) ; let sum = 0 ; let m = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { sum += Math . ceil ( arr [ i ] ) ; A [ i ] = Math . ceil ( arr [ i ] ) ; } if ( sum > 0 ) { m = Math . min ( sum , N ) ; for ( let i = 0 ; i < N && m > 0 ; i ++ ) { A [ i ] = Math . floor ( arr [ i ] ) ; if ( A [ i ] != Math . floor ( arr [ i ] ) ) m -- ; } } for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let arr = [ - 2 , - 2 , 4.5 ] ; let N = arr . length ; setSumtoZero ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, m, sum
Iterator variables: i
Javascript program:
function Get ( graph , a ) { return ( graph [ a ] = graph [ a ] == a ? a : Get ( graph , graph [ a ] ) ) ; } function Union ( graph , a , b ) { a = Get ( graph , a ) ; b = Get ( graph , b ) ; graph [ a ] = b ; } function Queries ( queries , N , M ) { let graph = new Array ( N ) . fill ( 2 ) ; for ( let i = 1 ; i <= N + 1 ; i ++ ) { graph [ i ] = i ; } for ( let query of queries ) { if ( query [ 0 ] == 1 ) { Union ( graph , query [ 1 ] , query [ 1 ] + 1 ) ; } else { let a = Get ( graph , query [ 1 ] ) ; if ( a == N + 1 ) document . write ( - 1 + " " ) ; else document . write ( graph [ a ] + " " ) ; } } } let N = 5 ; let queries = [ [ 2 , 1 ] , [ 1 , 1 ] , [ 2 , 1 ] , [ 2 , 3 ] , ] ; let Q = queries . length ; Queries ( queries , N , Q ) ;

Index/key variables: a, i
Accumulator variables: i
Iterator variables: i, query