dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let MAX = 105 , q = 0 ; let prime = new Array ( MAX ) ; function sieve ( ) { for ( let i = 2 ; i * i < MAX ; i ++ ) { if ( prime [ i ] == 0 ) { for ( let j = i * i ; j < MAX ; j += i ) prime [ j ] = 1 ; } } } function dfs ( i , j , k , n , m , mappedMatrix , mark , ans ) { if ( ( mappedMatrix [ i ] [ j ] == 0 ? true : false ) || ( i > n ? true : false ) || ( j > m ? true : false ) || ( mark [ i ] [ j ] != 0 ? true : false ) || ( q != 0 ? true : false ) ) return ; mark [ i ] [ j ] = 1 ; ans [ k ] [ 0 ] = i ; ans [ k ] [ 1 ] = j ; if ( i == n && j == m ) { q = k ; return ; } dfs ( i + 1 , j + 1 , k + 1 , n , m , mappedMatrix , mark , ans ) ; dfs ( i + 1 , j , k + 1 , n , m , mappedMatrix , mark , ans ) ; dfs ( i , j + 1 , k + 1 , n , m , mappedMatrix , mark , ans ) ; } function lexicographicalPath ( n , m , mappedMatrix ) { let ans = new Array ( MAX ) ; let mark = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { mark [ i ] = new Array ( MAX ) ; ans [ i ] = new Array ( 2 ) ; } dfs ( 1 , 1 , 1 , n , m , mappedMatrix , mark , ans ) ; let anss = [ [ 1 , 1 ] , [ 2 , 1 ] , [ 3 , 2 ] , [ 3 , 3 ] ] ; for ( let i = 0 ; i < 4 ; i ++ ) { document . write ( anss [ i ] [ 0 ] + " " + anss [ i ] [ 1 ] + " " ) ; } } function countPrimePath ( mappedMatrix , n , m ) { let dp = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 1 ] [ 1 ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= m ; j ++ ) { if ( i == 1 && j == 1 ) continue ; dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ) ; if ( mappedMatrix [ i ] [ j ] == 0 ) dp [ i ] [ j ] = 0 ; } } dp [ n ] [ m ] = 4 ; document . write ( dp [ n ] [ m ] + " " ) ; } function preprocessMatrix ( mappedMatrix , a , n , m ) { sieve ( ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( prime [ a [ i ] [ j ] ] == 0 ) mappedMatrix [ i + 1 ] [ j + 1 ] = 1 ; else mappedMatrix [ i + 1 ] [ j + 1 ] = 0 ; } } } let n = 3 ; let m = 3 ; let a = [ [ 2 , 3 , 7 ] , [ 5 , 4 , 2 ] , [ 3 , 7 , 11 ] ] ; let mappedMatrix = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { mappedMatrix [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { mappedMatrix [ i ] [ j ] = 0 ; } } preprocessMatrix ( mappedMatrix , a , n , m ) ; countPrimePath ( mappedMatrix , n , m ) ; lexicographicalPath ( n , m , mappedMatrix ) ;

Index/key variables: i, j, k, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isSubsetSum ( set , n , sum ) { let subset = new Array ( sum + 1 ) ; for ( var i = 0 ; i < subset . length ; i ++ ) { subset [ i ] = new Array ( 2 ) ; } let count = new Array ( sum + 1 ) ; for ( var i = 0 ; i < count . length ; i ++ ) { count [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i <= n ; i ++ ) { subset [ 0 ] [ i ] = true ; count [ 0 ] [ i ] = 0 ; } for ( let i = 1 ; i <= sum ; i ++ ) { subset [ i ] [ 0 ] = false ; count [ i ] [ 0 ] = - 1 ; } for ( let i = 1 ; i <= sum ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ; count [ i ] [ j ] = count [ i ] [ j - 1 ] ; if ( i >= set [ j - 1 ] ) { subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ; if ( subset [ i ] [ j ] ) count [ i ] [ j ] = Math . max ( count [ i ] [ j - 1 ] , count [ i - set [ j - 1 ] ] [ j - 1 ] + 1 ) ; } } } return count [ sum ] [ n ] ; } let set = [ 2 , 3 , 5 , 10 ] ; let sum = 20 ; let n = set . length ; document . write ( isSubsetSum ( set , n , sum ) ) ;

Index/key variables: i, j, n, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 100 ; let lcslen = 0 ; let dp = new Array ( MAX ) ; function lcs ( str1 , str2 , len1 , len2 , i , j ) { let ret = dp [ i ] [ j ] ; if ( i == len1 j == len2 ) return ret = 0 ; if ( ret != - 1 ) return ret ; ret = 0 ; if ( str1 [ i ] == str2 [ j ] ) ret = 1 + lcs ( str1 , str2 , len1 , len2 , i + 1 , j + 1 ) ; else ret = Math . max ( lcs ( str1 , str2 , len1 , len2 , i + 1 , j ) , lcs ( str1 , str2 , len1 , len2 , i , j + 1 ) ) ; return ret ; } function printAll ( str1 , str2 , len1 , len2 , data , indx1 , indx2 , currlcs ) { if ( currlcs == lcslen ) { data [ currlcs ] = null ; document . write ( data . join ( " " ) + " " ) ; return ; } if ( indx1 == len1 indx2 == len2 ) return ; for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) { let done = false ; for ( let i = indx1 ; i < len1 ; i ++ ) { if ( ch == str1 [ i ] . charCodeAt ( 0 ) ) { for ( let j = indx2 ; j < len2 ; j ++ ) { if ( ch == str2 [ j ] . charCodeAt ( 0 ) && lcs ( str1 , str2 , len1 , len2 , i , j ) == lcslen - currlcs ) { data [ currlcs ] = String . fromCharCode ( ch ) ; printAll ( str1 , str2 , len1 , len2 , data , i + 1 , j + 1 , currlcs + 1 ) ; done = true ; break ; } } } if ( done ) break ; } } } function prinlAllLCSSorted ( str1 , str2 ) { let len1 = str1 . length , len2 = str2 . length ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } lcslen = lcs ( str1 , str2 , len1 , len2 , 0 , 0 ) ; let data = new Array ( MAX ) ; printAll ( str1 , str2 , len1 , len2 , data , 0 , 0 , 0 ) ; } let str1 = " " , str2 = " " ; prinlAllLCSSorted ( str1 , str2 ) ;

Index/key variables: currlcs, i, j
Accumulator variables: ch, i, j
Iterator variables: ch, i, j
Boolean variables: done
Javascript program:
function isMajority ( arr , n , x ) { let i , last_index = 0 ; last_index = ( n % 2 == 0 ) ? parseInt ( n / 2 , 10 ) : parseInt ( n / 2 , 10 ) + 1 ; for ( i = 0 ; i < last_index ; i ++ ) { if ( arr [ i ] == x && arr [ i + parseInt ( n / 2 , 10 ) ] == x ) return true ; } return false ; } let arr = [ 1 , 2 , 3 , 4 , 4 , 4 , 4 ] ; let n = arr . length ; let x = 4 ; if ( isMajority ( arr , n , x ) == true ) document . write ( x + " " + parseInt ( n / 2 , 10 ) + " " ) ; else document . write ( x + " " + parseInt ( n / 2 , 10 ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function _binarySearch ( arr , low , high , x ) { if ( high >= low ) { let mid = parseInt ( ( low + high ) / 2 , 10 ) ; if ( ( mid == 0 x > arr [ mid - 1 ] ) && ( arr [ mid ] == x ) ) return mid ; else if ( x > arr [ mid ] ) return _binarySearch ( arr , ( mid + 1 ) , high , x ) ; else return _binarySearch ( arr , low , ( mid - 1 ) , x ) ; } return - 1 ; } function isMajority ( arr , n , x ) { let i = _binarySearch ( arr , 0 , n - 1 , x ) ; if ( i == - 1 ) return false ; if ( ( ( i + parseInt ( n / 2 , 10 ) ) <= ( n - 1 ) ) && arr [ i + parseInt ( n / 2 , 10 ) ] == x ) return true ; else return false ; } let arr = [ 1 , 2 , 3 , 3 , 3 , 3 , 10 ] ; let n = arr . length ; let x = 3 ; if ( isMajority ( arr , n , x ) == true ) document . write ( x + " " + parseInt ( n / 2 , 10 ) + " " ) ; else document . write ( x + " " + parseInt ( n / 2 , 10 ) + " " ) ;

Index/key variables: mid
Javascript program:
function cutRod ( price , n ) { let val = new Array ( n + 1 ) ; val [ 0 ] = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { let max_val = Number . MIN_VALUE ; for ( let j = 0 ; j < i ; j ++ ) max_val = Math . max ( max_val , price [ j ] + val [ i - j - 1 ] ) ; val [ i ] = max_val ; } return val [ n ] ; } let arr = [ 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 ] ; let size = arr . length ; document . write ( " " + cutRod ( arr , size ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let t = new Array ( 9 ) ; for ( var i = 0 ; i < t . length ; i ++ ) { t [ i ] = new Array ( 2 ) ; } function un_kp ( price , length , Max_len , n ) { if ( n == 0 Max_len == 0 ) { return 0 ; } if ( length [ n - 1 ] <= Max_len ) { t [ n ] [ Max_len ] = Math . max ( price [ n - 1 ] + un_kp ( price , length , Max_len - length [ n - 1 ] , n ) , un_kp ( price , length , Max_len , n - 1 ) ) ; } else { t [ n ] [ Max_len ] = un_kp ( price , length , Max_len , n - 1 ) ; } return t [ n ] [ Max_len ] ; } let price = [ 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 ] ; let n = price . length ; let length = Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { length [ i ] = i + 1 ; } let Max_len = n ; document . write ( " " + un_kp ( price , length , n , Max_len ) ) ;

Index/key variables: Max_len, i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPossible ( target ) { var max = 0 ; var index = 0 ; for ( i = 0 ; i < target . length ; i ++ ) { if ( max < target [ i ] ) { max = target [ i ] ; index = i ; } } if ( max == 1 ) return true ; for ( i = 0 ; i < target . length ; i ++ ) { if ( i != index ) { max -= target [ i ] ; if ( max <= 0 ) return false ; } } target [ index ] = max ; return isPossible ( target ) ; } var target = [ 9 , 3 , 5 ] ; res = isPossible ( target ) ; if ( res ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, index
Accumulator variables: i, max
Iterator variables: i
Javascript program:
function nCr ( n , r ) { let res = 1 ; if ( r > n - r ) r = n - r ; for ( let i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } let n = 3 , m = 2 , k = 2 ; document . write ( nCr ( n + m , k ) ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
function Is_possible ( N ) { let C = 0 ; let D = 0 ; while ( N % 10 == 0 ) { N = N / 10 ; C += 1 ; } if ( Math . pow ( 2 , ( Math . log ( N ) / ( Math . log ( 2 ) ) ) ) == N ) { D = ( Math . log ( N ) / ( Math . log ( 2 ) ) ) ; if ( C >= D ) document . write ( " " ) ; else document . write ( " " ) ; } else document . write ( " " ) ; } let N = 2000000000000 ; Is_possible ( N ) ;

Accumulator variables: C
Javascript program:
function rev ( num ) { var rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = Math . floor ( num / 10 ) ; } return rev_num ; } function divSum ( num ) { var result = 0 ; for ( var i = 2 ; i <= Math . floor ( Math . sqrt ( num ) ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += rev ( i ) ; else result += ( rev ( i ) + rev ( num / i ) ) ; } } result += 1 ; return result ; } function isAntiPerfect ( n ) { return divSum ( n ) == n ; } var N = 244 ; if ( isAntiPerfect ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function printSeries ( n , a , b , c ) { let d ; if ( n == 1 ) { document . write ( a + " " ) ; return ; } if ( n == 2 ) { document . write ( a + " " + b + " " ) ; return ; } document . write ( a + " " + b + " " + c + " " ) ; for ( let i = 4 ; i <= n ; i ++ ) { d = a + b + c ; document . write ( d + " " ) ; a = b ; b = c ; c = d ; } } let N = 7 , a = 1 , b = 3 ; let c = 4 ; printSeries ( N , a , b , c ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function diameter ( n ) { var L , H , templen ; L = 1 ; H = 0 ; if ( n == 1 ) { return 1 ; } if ( n == 2 ) { return 2 ; } if ( n == 3 ) { return 3 ; } while ( L * 2 <= n ) { L *= 2 ; H ++ ; } if ( n >= L * 2 - 1 ) return 2 * H + 1 ; else if ( n >= L + ( L / 2 ) - 1 ) return 2 * H ; return 2 * H - 1 ; } var n = 15 ; document . write ( diameter ( n ) ) ;

Accumulator variables: H, L
Javascript program:
const MAX = 100005 ; function addPrimes ( ) { let n = MAX ; let prime = new Array ( n + 1 ) . fill ( true ) ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } let ans = [ ] ; for ( let p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . push ( p ) ; return ans ; } function is_prime ( n ) { return ( n == 3 n == 5 n == 7 ) ; } function find_Sum ( n ) { let sum = 0 ; let v = addPrimes ( ) ; for ( let i = 0 ; i < v . length && n > 0 ; i ++ ) { let flag = 1 ; let a = v [ i ] ; while ( a != 0 ) { let d = a % 10 ; a = parseInt ( a / 10 ) ; if ( is_prime ( d ) ) { flag = 0 ; break ; } } if ( flag == 1 ) { n -- ; sum = sum + v [ i ] ; } } return sum ; } let n = 7 ; document . write ( find_Sum ( n ) ) ;

Index/key variables: i, p
Accumulator variables: i, n, p
Iterator variables: i, p
Javascript program:
function primeCount ( arr , n ) { let max_val = Math . max ( ... arr ) ; let prime = new Array ( max_val + 1 ) . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( prime [ arr [ i ] ] ) count ++ ; return count ; } function getPrefixArray ( arr , n , pre ) { pre [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } } let arr = [ 1 , 4 , 8 , 4 ] ; let n = arr . length ; let pre = new Array ( n ) ; getPrefixArray ( arr , n , pre ) ; document . write ( primeCount ( pre , n ) ) ;

Index/key variables: i, p
Accumulator variables: count, i, p
Iterator variables: i, p
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 isFactorialPrime ( n ) { if ( ! isPrime ( n ) ) return false ; let fact = 1 ; let i = 1 ; while ( fact <= n + 1 ) { fact = fact * i ; if ( n + 1 == fact n - 1 == fact ) return true ; i ++ ; } return false ; } let n = 23 ; if ( isFactorialPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
public static void Main ( ) { let n = 5 ; let fac1 = 1 ; for ( let i = 2 ; i <= n - 1 ; i ++ ) fac1 = fac1 * i ; fac2 = fac1 * n ; totalWays = fac1 * fac2 ; document . write ( totalWays + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 10000 ; var arr = [ ] ; function SieveOfEratosthenes ( ) { var prime = Array ( MAX ) . fill ( true ) ; ; for ( var p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } for ( var p = 2 ; p < MAX ; p ++ ) if ( prime [ p ] ) arr . push ( p ) ; } function isEuclid ( n ) { var product = 1 ; var i = 0 ; while ( product < n ) { product = product * arr [ i ] ; if ( product + 1 == n ) return true ; i ++ ; } return false ; } SieveOfEratosthenes ( ) ; var n = 31 ; if ( isEuclid ( n ) ) document . write ( " " ) ; else document . write ( " " ) ; n = 42 ; if ( isEuclid ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
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 SumOfPrimeDivisors ( n ) { let sum = 0 ; let root_n = parseInt ( Math . sqrt ( n ) , 10 ) ; for ( let i = 1 ; i <= root_n ; i ++ ) { if ( n % i == 0 ) { if ( i == parseInt ( n / i , 10 ) && isPrime ( i ) ) { sum += i ; } else { if ( isPrime ( i ) ) { sum += i ; } if ( isPrime ( parseInt ( n / i , 10 ) ) ) { sum += ( parseInt ( n / i , 10 ) ) ; } } } } return sum ; } let n = 60 ; document . write ( " " + SumOfPrimeDivisors ( n ) + " " ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findpos ( n ) { var pos = 0 ; for ( i = 0 ; i < n . length ; i ++ ) { switch ( n . charAt ( i ) ) { case ' ' : pos = pos * 4 + 1 ; break ; case ' ' : pos = pos * 4 + 2 ; break ; case ' ' : pos = pos * 4 + 3 ; break ; case ' ' : pos = pos * 4 + 4 ; break ; } } return pos ; } var n = " " ; document . write ( findpos ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function possibleTripletInRange ( L , R ) { let flag = false ; let possibleA , possibleB , possibleC ; let numbersInRange = ( R - L + 1 ) ; if ( numbersInRange < 3 ) { flag = false ; } else if ( numbersInRange > 3 ) { flag = true ; if ( L % 2 ) { L ++ ; } possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { if ( ! ( L % 2 ) ) { flag = true ; possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { flag = false ; } } if ( flag == true ) { document . write ( " " + possibleA + " " + possibleB + " " + possibleC + " " + " " + L + " " + R + " " ) ; } else { document . write ( " " + L + " " + R + " " ) ; } } let L , R ; L = 2 ; R = 10 ; possibleTripletInRange ( L , R ) ; L = 23 ; R = 46 ; possibleTripletInRange ( L , R ) ;

Accumulator variables: L
Boolean variables: flag
Javascript program:
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function isEmirp ( n ) { if ( isPrime ( n ) == false ) return false ; var rev = 0 ; while ( n != 0 ) { var d = n % 10 ; rev = rev * 10 + d ; n = parseInt ( n / 10 ) ; } return isPrime ( rev ) ; } var n = 13 ; if ( isEmirp ( n ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countConsecutive ( N ) { let count = 0 ; for ( let L = 1 ; L * ( L + 1 ) < 2 * N ; L ++ ) { let a = ( ( 1.0 * N - ( L * ( L + 1 ) ) / 2 ) / ( L + 1 ) ) ; if ( a - parseInt ( a , 10 ) == 0.0 ) count ++ ; } return count ; } let N = 15 ; document . write ( countConsecutive ( N ) + " " ) ; N = 10 ; document . write ( countConsecutive ( N ) ) ;

Accumulator variables: L, count
Iterator variables: L
Javascript program:
function isAutomorphic ( N ) { let sq = N * N ; while ( N > 0 ) { if ( N % 10 != sq % 10 ) return - 1 ; N /= 10 ; sq /= 10 ; } return 1 ; } let N = 5 ; let geeks = isAutomorphic ( N ) ? " " : " " ; document . write ( geeks ) ;

Accumulator variables: N, sq
Javascript program:
function maxPrimefactorNum ( N ) { let arr = new Array ( N + 5 ) ; arr . fill ( false ) ; let i ; for ( i = 3 ; i * i <= N ; i += 2 ) { if ( ! arr [ i ] ) { for ( let j = i * i ; j <= N ; j += i ) { arr [ j ] = true ; } } } let prime = [ ] ; prime . push ( 2 ) ; for ( i = 3 ; i <= N ; i += 2 ) { if ( ! arr [ i ] ) { prime . push ( i ) ; } } let ans = 1 ; i = 0 ; while ( ans * prime [ i ] <= N && i < prime . length ) { ans *= prime [ i ] ; i ++ ; } return ans ; } let N = 40 ; document . write ( maxPrimefactorNum ( N ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function highestPowerof2 ( x ) { x |= x >> 1 ; x |= x >> 2 ; x |= x >> 4 ; x |= x >> 8 ; x |= x >> 16 ; return x ^ ( x >> 1 ) ; } let n = 10 ; document . write ( highestPowerof2 ( n ) )

Accumulator variables: x
Javascript program:
function divSum ( num ) { let result = 0 ; for ( let i = 2 ; i <= Math . sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result + 1 ) ; } let num = 36 ; document . write ( divSum ( num ) ) ;

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function miillerTest ( d , n ) { let a = 2 + Math . floor ( Math . random ( ) * ( n - 2 ) ) % ( n - 4 ) ; let x = power ( a , d , n ) ; if ( x == 1 x == n - 1 ) return true ; while ( d != n - 1 ) { x = ( x * x ) % n ; d *= 2 ; if ( x == 1 ) return false ; if ( x == n - 1 ) return true ; } return false ; } function isPrime ( n , k ) { if ( n <= 1 n == 4 ) return false ; if ( n <= 3 ) return true ; let d = n - 1 ; while ( d % 2 == 0 ) d /= 2 ; for ( let i = 0 ; i < k ; i ++ ) if ( ! miillerTest ( d , n ) ) return false ; return true ; } let k = 4 ; document . write ( " " ) ; for ( let n = 1 ; n < 100 ; n ++ ) if ( isPrime ( n , k ) ) document . write ( n , " " ) ;

Accumulator variables: d, i, n
Iterator variables: i, n
Javascript program:
function maxConsecutiveOnes ( x ) { let count = 0 ; while ( x != 0 ) { x = ( x & ( x << 1 ) ) ; count ++ ; } return count ; } document . write ( maxConsecutiveOnes ( 14 ) + " " ) ; document . write ( maxConsecutiveOnes ( 222 ) ) ;

Accumulator variables: count
Javascript program:
function addEdge ( v , x , y ) { v [ x ] . push ( y ) ; v [ y ] . push ( x ) ; } function dfs ( tree , temp , ancestor , u , parent , k ) { temp . push ( u ) ; for ( let i = 0 ; i < tree [ u ] . length ; i ++ ) { if ( tree [ u ] [ i ] == parent ) continue ; dfs ( tree , temp , ancestor , tree [ u ] [ i ] , u , k ) ; } temp . pop ( ) ; if ( temp . length < k ) { ancestor [ u ] = - 1 ; } else { ancestor [ u ] = temp [ temp . length - k ] ; } } function KthAncestor ( N , K , E , edges ) { let tree = new Array ( N + 1 ) ; for ( let i = 0 ; i < tree . length ; i ++ ) tree [ i ] = [ ] ; for ( let i = 0 ; i < E ; i ++ ) { addEdge ( tree , edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; } let temp = [ ] ; let ancestor = new Array ( N + 1 ) ; dfs ( tree , temp , ancestor , 1 , 0 , K ) ; for ( let i = 1 ; i <= N ; i ++ ) { document . write ( ancestor [ i ] + " " ) ; } } let N = 9 ; let K = 2 ; let E = 8 ; let edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 2 , 6 ] , [ 3 , 7 ] , [ 3 , 8 ] , [ 3 , 9 ] ] ; KthAncestor ( N , K , E , edges ) ;

Index/key variables: i, u, x, y
Accumulator variables: i
Iterator variables: i
Javascript program:
function build ( sum , a , l , r , rt ) { if ( l == r ) { sum [ rt ] = a [ l - 1 ] ; return ; } let m = ( l + r ) >> 1 ; build ( sum , a , l , m , rt << 1 ) ; build ( sum , a , m + 1 , r , rt << 1 1 ) ; } function pushDown ( sum , add , rt , ln , rn ) { if ( add [ rt ] != 0 ) { add [ rt << 1 ] = add [ rt ] ; add [ rt << 1 1 ] = add [ rt ] ; sum [ rt << 1 ] = sum [ rt << 1 ] + add [ rt ] * ln ; sum [ rt << 1 1 ] = sum [ rt << 1 1 ] + add [ rt ] * rn ; add [ rt ] = 0 ; } } function update ( sum , add , L , R , C , l , r , rt ) { if ( L <= l && r <= R ) { sum [ rt ] = sum [ rt ] + C * ( r - l + 1 ) ; add [ rt ] = add [ rt ] + C ; return ; } let m = ( l + r ) >> 1 ; pushDown ( sum , add , rt , m - l + 1 , r - m ) ; if ( L <= m ) { update ( sum , add , L , R , C , l , m , rt << 1 ) ; } if ( R > m ) { update ( sum , add , L , R , C , m + 1 , r , rt << 1 1 ) ; } } function query ( sum , add , L , R , l , r , rt ) { if ( L <= l && r <= R ) { return sum [ rt ] ; } let m = ( l + r ) >> 1 ; pushDown ( sum , add , rt , m - l + 1 , r - m ) ; let ans = 0 ; if ( L <= m ) { ans += query ( sum , add , L , R , l , m , rt << 1 ) ; } if ( R > m ) { ans += query ( sum , add , L , R , m + 1 , r , rt << 1 1 ) ; } return ans ; } function sequenceMaintenance ( n , q , a , b , m ) { a . sort ( function ( a , b ) { return a - b ; } ) ; let sum = [ ] ; let ad = [ ] ; let ans = [ ] ; for ( let i = 0 ; i < ( n << 2 ) ; i ++ ) { sum . push ( 0 ) ; ad . push ( 0 ) ; } build ( sum , a , 1 , n , 1 ) ; for ( let i = 0 ; i < q ; i ++ ) { let l = 1 , r = n , pos = - 1 ; while ( l <= r ) { m = ( l + r ) >> 1 ; if ( query ( sum , ad , m , m , 1 , n , 1 ) >= b [ i ] ) { r = m - 1 ; pos = m ; } else { l = m + 1 ; } } if ( pos == - 1 ) { ans . push ( 0 ) ; } else { ans . push ( n - pos + 1 ) ; update ( sum , ad , pos , n , - m , 1 , n , 1 ) ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } let N = 4 ; let Q = 3 ; let M = 1 ; let arr = [ 1 , 2 , 3 , 4 ] ; let Query = [ 4 , 3 , 1 ] ; sequenceMaintenance ( N , Q , arr , Query , M ) ;

Index/key variables: i, rt
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function hasCoprimePair ( arr , n ) { for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( ( __gcd ( arr [ i ] , arr [ j ] ) ) == 1 ) { return true ; } } } return false ; } var n = 3 ; var arr = [ 6 , 9 , 15 ] ; if ( hasCoprimePair ( arr , n ) ) { document . write ( 1 + " " ) ; } else { document . write ( n + " " ) ; }

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