dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function calcScr ( arr ) { let ans = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) ans += ( i ^ arr [ i ] ) ; return ans ; } function getMax ( arr , ans , chosen , N ) { if ( arr . length == N ) { ans = Math . max ( ans , calcScr ( arr ) ) ; return ans ; } for ( let i = 0 ; i < N ; i ++ ) { if ( chosen [ i ] ) continue ; chosen [ i ] = true ; arr . push ( i ) ; ans = getMax ( arr , ans , chosen , N ) ; chosen [ i ] = false ; arr . pop ( ) ; } return ans ; } let N = 2 ; let arr = [ ] ; let ans = - 1 ; let chosen = new Array ( N ) . fill ( false ) ; ans = getMax ( arr , ans , chosen , N ) ; document . write ( ans + " " ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function additiveCongruentialMethod ( Xo , m , c , randomNums , noOfRandomNums ) { randomNums [ 0 ] = Xo ; for ( let i = 1 ; i < noOfRandomNums ; i ++ ) { randomNums [ i ] = ( randomNums [ i - 1 ] + c ) % m ; } } let Xo = 3 ; let m = 15 ; let c = 2 ; let noOfRandomNums = 20 ; let randomNums = new Array ( noOfRandomNums ) . fill ( 0 ) ; additiveCongruentialMethod ( Xo , m , c , randomNums , noOfRandomNums ) ; for ( let i = 0 ; i < noOfRandomNums ; i ++ ) { document . write ( randomNums [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lastElement ( arr ) { let pq = [ ] ; for ( let i = 0 ; i < arr . length ; i ++ ) { pq . push ( arr [ i ] ) ; } let m1 , m2 ; while ( pq . length ) { if ( pq . length == 1 ) return pq [ pq . length - 1 ] ; pq . sort ( ( a , b ) => a - b ) m1 = pq [ pq . length - 1 ] ; pq . pop ( ) ; m2 = pq [ pq . length - 1 ] ; pq . pop ( ) ; if ( m1 != m2 ) pq . push ( m1 - m2 ) ; } return 0 ; } let arr = [ 2 , 7 , 4 , 1 , 8 , 1 , 1 ] ; document . write ( lastElement ( arr ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function prod_of_max_min ( n ) { var largest = 0 ; var smallest = 10 ; while ( n ) { var r = n % 10 ; largest = Math . max ( r , largest ) ; smallest = Math . min ( r , smallest ) ; n = parseInt ( n / 10 ) ; } return largest * smallest ; } function formed_no ( N , K ) { if ( K == 1 ) { return N ; } var answer = N ; while ( K -- ) { var a_current = prod_of_max_min ( answer ) ; if ( a_current == 0 ) break ; answer += a_current ; } return answer ; } var N = 487 , K = 100000000 ; document . write ( formed_no ( N , K ) + " " ) ;

Accumulator variables: K, answer
Javascript program:
function sum ( x , n ) { let i , total = 1.0 , multi = x ; document . write ( total + " " ) ; for ( i = 1 ; i < n ; i ++ ) { total = total + multi ; document . write ( multi + " " ) ; multi = multi * x ; } document . write ( " " ) ; return total ; } let x = 2 ; let n = 5 ; document . write ( sum ( x , n ) . toFixed ( 2 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkPalindrome ( num ) { let str = num . toString ( ) ; let l = 0 , r = str . length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { document . write ( " " ) ; return ; } l ++ ; r -- ; } document . write ( " " ) ; return ; } let n = 19 , k = 3 ; checkPalindrome ( n + k ) ;

Index/key variables: l, r
Accumulator variables: l, r
Javascript program:
function subsetSum ( arr , n , i , sum , count ) { if ( i == n ) { if ( sum == 0 ) { count ++ ; } return count ; } count = subsetSum ( arr , n , i + 1 , sum - arr [ i ] , count ) ; count = subsetSum ( arr , n , i + 1 , sum , count ) ; return count ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var sum = 10 ; var n = arr . length ; document . write ( subsetSum ( arr , n , 0 , sum , 0 ) ) ;

Index/key variables: i
Accumulator variables: count
Javascript program:
function sieve ( n ) { let prime = [ ] ; for ( let i = 0 ; i < n + 1 ; i ++ ) prime . push ( 0 ) ; let p = 2 ; while ( p * p <= n ) { if ( prime [ p ] == 0 ) { for ( let i = 2 * p ; i < n + 1 ; i += p ) prime [ i ] = 1 ; } p += 1 ; } let allPrimes = [ ] ; for ( let i = 2 ; i < n ; i ++ ) { if ( prime [ i ] == 0 ) allPrimes . push ( i ) ; } return allPrimes ; } function distPrime ( arr , allPrimes ) { let list1 = [ ] ; for ( let i = 0 ; i < allPrimes . length ; i ++ ) { for ( let j = 0 ; j < arr . length ; j ++ ) { if ( arr [ j ] % allPrimes [ i ] == 0 ) { list1 . push ( allPrimes [ i ] ) ; break ; } } } return list1 ; } let allPrimes = sieve ( 10000 ) ; let arr = [ ] ; arr . push ( 15 ) ; arr . push ( 30 ) ; arr . push ( 60 ) ; let ans = distPrime ( arr , allPrimes ) ; document . write ( " " ) ; for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ; document . write ( " " ) ;

Index/key variables: i, j, p
Accumulator variables: i, j, p
Iterator variables: i, j
Javascript program:
function count ( arr , n , k ) { arr . sort ( ) ; var cnt = 0 ; var i = 0 ; var j = 1 ; while ( i < n && j < n ) { if ( j <= i ) j = i + 1 else j = j while ( j < n && ( arr [ j ] - arr [ i ] ) < k ) j += 1 ; cnt += ( n - j ) ; i += 1 ; } return cnt ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var k = 2 ; document . write ( count ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Javascript program:
function count_square ( n ) { let count = 0 ; for ( let i = 1 ; i <= n ; i = i + 2 ) { let k = n - i + 1 ; count += ( k * k ) ; } return count ; } let N = 8 ; document . write ( count_square ( N ) ) ;

Accumulator variables: count
Iterator variables: i
Javascript program:
function countAnomalies ( arr , n , k ) { var cnt = 0 ; var i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( Math . abs ( arr [ i ] - ( sum - arr [ i ] ) ) > k ) cnt ++ ; return cnt ; } var arr = [ 1 , 3 , 5 ] ; var n = arr . length ; var k = 1 ; document . write ( countAnomalies ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, sum
Iterator variables: i
Javascript program:
const N = 100005 ; let d = new Array ( N ) . fill ( 0 ) ; let pre = new Array ( N ) . fill ( 0 ) ; function Positive_Divisors ( ) { for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) d [ i ] ++ ; else d [ i ] += 2 ; } } } let ans = 0 ; for ( let i = 2 ; i < N ; i ++ ) { if ( d [ i ] == d [ i - 1 ] ) ans ++ ; pre [ i ] = ans ; } } Positive_Divisors ( ) ; let n = 15 ; document . write ( pre [ n ] ) ;

Index/key variables: i, n
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function numLen ( K ) { if ( K % 2 == 0 K % 5 == 0 ) { return - 1 ; } var number = 0 ; var len = 1 ; for ( len = 1 ; len <= K ; len ++ ) { number = number * 10 + 1 ; if ( ( number % K == 0 ) ) { return len ; } } return - 1 ; } var K = 7 ; document . write ( numLen ( K ) ) ;

Accumulator variables: len
Iterator variables: len
Javascript program:
function printPermutation ( n , k ) { for ( var i = 1 ; i <= n ; i ++ ) { var x = 2 * i - 1 ; var y = 2 * i ; if ( i <= k ) document . write ( y + " " + x + " " ) ; else document . write ( x + " " + y + " " ) ; } } var n = 2 , k = 1 ; printPermutation ( n , k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( N ) { var ans = 0 ; for ( var u = 1 ; u <= N ; u ++ ) { for ( var v = 1 ; v <= N ; v ++ ) { if ( u == v ) continue ; var degreeU = 2 ; if ( u == 1 u == N ) degreeU = 1 ; var degreeV = 2 ; if ( v == 1 v == N ) degreeV = 1 ; ans += ( degreeU * degreeV ) ; } } return ans ; } var N = 6 ; document . write ( maxSum ( N ) ) ;

Accumulator variables: ans, u, v
Iterator variables: u, v
Javascript program:
function maximumFactor ( arr ) { var n = arr . length ; var rank = [ ] ; var factors = [ ] ; var max = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; for ( var i = 2 ; i <= max ; i ++ ) { var count = 0 ; for ( var j = 0 ; j < n ; j ++ ) { if ( arr [ j ] % i == 0 ) count += 1 ; rank . push ( count ) ; factors . push ( i ) ; } } var m = rank . reduce ( ( a , b ) => Math . max ( a , b ) ) ; for ( var i = 0 ; i < rank . length ; i ++ ) { if ( rank [ i ] == m ) document . write ( factors [ i ] + " " ) ; } } var arr = [ 120 , 15 , 24 , 63 , 18 ] ; maximumFactor ( arr ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function findSum ( n ) { let sum = 0 ; for ( x = 1 ; x <= n ; x ++ ) sum = sum + x ; return sum ; } n = 5 ; document . write ( findSum ( n ) ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function CheckArray ( arr , n ) { let prod = 1 ; let freq = [ ] ; for ( let i = 0 ; i < n ; ++ i ) { freq . push ( arr [ i ] ) ; prod *= arr [ i ] ; } let root = Math . floor ( Math . sqrt ( prod ) ) ; if ( root * root == prod ) { if ( freq . includes ( root ) & freq . lastIndexOf ( root ) != ( freq . length ) ) { return true ; } } return false ; } let arr = [ 1 , 2 , 12 , 3 , 2 ] ; let n = arr . length ; if ( CheckArray ( arr , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: prod
Iterator variables: i
Javascript program:
function minAreaRect ( points ) { let columns = new Set ( ) ; for ( let point = 0 ; point < points . length ; point ++ ) columns . add ( 40001 * points [ point ] [ 0 ] + points [ point ] [ 1 ] ) ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < points . length ; ++ i ) for ( let j = i + 1 ; j < points . length ; ++ j ) { if ( points [ i ] [ 0 ] != points [ j ] [ 0 ] && points [ i ] [ 1 ] != points [ j ] [ 1 ] ) { if ( columns . has ( 40001 * points [ i ] [ 0 ] + points [ j ] [ 1 ] ) && columns . has ( 40001 * points [ j ] [ 0 ] + points [ i ] [ 1 ] ) ) { ans = Math . min ( ans , Math . abs ( points [ j ] [ 0 ] - points [ i ] [ 0 ] ) * Math . abs ( points [ j ] [ 1 ] - points [ i ] [ 1 ] ) ) ; } } } return ans < Number . MAX_VALUE ? ans : 0 ; } let A = [ [ 1 , 1 ] , [ 1 , 3 ] , [ 3 , 1 ] , [ 3 , 3 ] , [ 2 , 2 ] ] ; document . write ( minAreaRect ( A ) ) ;

Index/key variables: i, j, point
Accumulator variables: point
Iterator variables: i, j, point
Javascript program:
function toK ( N , K ) { let w = 1 ; let s = 0 ; while ( N != 0 ) { let r = N % K ; N = parseInt ( N / K ) ; s = r * w + s ; w *= 10 ; } return s ; } function check ( N ) { let fl = false ; while ( N != 0 ) { let r = N % 10 ; N = parseInt ( N / 10 ) ; if ( fl == true && r == 0 ) return false ; if ( r > 0 ) { fl = false ; continue ; } fl = true ; } return true ; } function hasConsecutiveZeroes ( N , K ) { let z = toK ( N , K ) ; if ( check ( z ) ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 15 ; let K = 8 ; hasConsecutiveZeroes ( N , K ) ;

Accumulator variables: w
Boolean variables: fl
Javascript program:
let MAX = 100000 ; let prime = new Array ( MAX + 1 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { prime [ 1 ] = false ; prime [ 0 ] = false ; for ( let p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } function SumOfKthPrimes ( arr , n , k ) { let c = 0 ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { c ++ ; if ( c % k == 0 ) { sum += arr [ i ] ; c = 0 ; } } } document . write ( sum + " " ) ; } SieveOfEratosthenes ( ) ; let arr = new Array ( 2 , 3 , 5 , 7 , 11 ) ; let n = arr . length ; let k = 2 ; SumOfKthPrimes ( arr , n , k ) ;

Index/key variables: i, p
Accumulator variables: c, i, p, sum
Iterator variables: i, p
Javascript program:
var MAX = 100000 ; var prime = Array ( 100002 ) . fill ( true ) ; function SieveOfEratosthenes ( ) { for ( var p = 2 ; p * p <= MAX ; p ++ ) if ( prime [ p ] == true ) for ( var i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } function superpower ( n ) { SieveOfEratosthenes ( ) ; var superPower = 0 , factor = 0 ; var i = 2 ; while ( n > 1 && i <= MAX ) { if ( prime [ i ] ) { factor = 0 ; while ( n % i == 0 && n > 1 ) { factor ++ ; n = n / i ; } if ( superPower < factor ) superPower = factor ; } i ++ ; } return superPower ; } var n = 256 ; document . write ( superpower ( n ) ) ;

Index/key variables: i, p
Accumulator variables: factor, i, p
Iterator variables: i, p
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function countPrime ( head_ref ) { var count = 0 ; var ptr = head_ref ; while ( ptr != null ) { if ( isPrime ( ptr . data ) ) { count ++ ; } ptr = ptr . next ; } return count ; } var head = null ; head = push ( head , 17 ) ; head = push ( head , 10 ) ; head = push ( head , 6 ) ; head = push ( head , 5 ) ; head = push ( head , 15 ) ; document . write ( " " + countPrime ( head ) ) ;

Accumulator variables: count
Iterator variables: i
Class/struct names: Node
Javascript program:
function smallestDivisor ( n ) { if ( n % 2 == 0 ) return 2 ; for ( var i = 3 ; i * i <= n ; i += 2 ) { if ( n % i == 0 ) return i ; } return n ; } var n = 31 ; document . write ( smallestDivisor ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function xorEqualsOrCount ( N ) { let count = 0 ; let bit ; while ( N > 0 ) { bit = N % 2 ; if ( bit == 0 ) count ++ ; N = parseInt ( N / 2 ) ; } return Math . pow ( 2 , count ) ; } let N = 7 ; document . write ( xorEqualsOrCount ( N ) ) ;

Accumulator variables: count
Javascript program:
function fact ( n ) { if ( n == 1 ) return 1 ; return n * fact ( n - 1 ) ; } function sum ( x , n ) { let total = 1.0 ; for ( let i = 1 ; i <= n ; i ++ ) { total = total + ( Math . pow ( x , i ) / fact ( i + 1 ) ) ; } return total . toFixed ( 4 ) ; } let x = 5 ; let n = 4 ; document . write ( " " + sum ( x , n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sum_of_series ( n ) { var result = 0 ; for ( i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) result = result - parseInt ( Math . pow ( i , 2 ) ) ; else result = result + parseInt ( Math . pow ( i , 2 ) ) ; } return result ; } var n = 3 ; document . write ( sum_of_series ( n ) + " " ) ; n = 10 ; document . write ( sum_of_series ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
MAX = 16 var nCr = Array . from ( Array ( MAX ) , ( ) => new Array ( MAX ) ) ; function binomial ( ) { for ( var i = 0 ; i < MAX ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] ; } } } function findCosNTheta ( sinTheta , n ) { var cosTheta = Math . sqrt ( 1 - sinTheta * sinTheta ) ; var ans = 0 ; var toggle = 1 ; for ( var i = 1 ; i <= n ; i += 2 ) { ans = ans + nCr [ n ] [ i ] * Math . pow ( cosTheta , n - i ) * Math . pow ( sinTheta , i ) * toggle ; toggle = toggle * - 1 ; } return ans . toFixed ( 6 ) ; } binomial ( ) ; var sinTheta = 0.5 ; var n = 10 ; document . write ( findCosNTheta ( sinTheta , n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
MAX = 16 var nCr = Array . from ( Array ( MAX ) , ( ) => new Array ( MAX ) ) ; function binomial ( ) { for ( var i = 0 ; i < MAX ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] ; } } } function findCosnTheta ( cosTheta , n ) { var sinTheta = Math . sqrt ( 1 - cosTheta * cosTheta ) ; var ans = 0 ; var toggle = 1 ; for ( var i = 0 ; i <= n ; i += 2 ) { ans = ans + nCr [ n ] [ i ] * Math . pow ( cosTheta , n - i ) * Math . pow ( sinTheta , i ) * toggle ; toggle = toggle * - 1 ; } return ans . toFixed ( 1 ) ; } binomial ( ) ; var cosTheta = 0.5 ; var n = 10 ; document . write ( findCosnTheta ( cosTheta , n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPower ( a ) { if ( a == 1 ) return true ; for ( let i = 2 ; i * i <= a ; i ++ ) { let val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - Math . floor ( val ) ) < 0.00000001 ) return true ; } return false ; } let n = 16 ; document . write ( isPower ( n ) ? " " : " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function rmsValue ( arr , n ) { var square = 0 ; var mean = 0 ; var root = 0 ; for ( i = 0 ; i < n ; i ++ ) { square += Math . pow ( arr [ i ] , 2 ) ; } mean = ( square / ( n ) ) ; root = Math . sqrt ( mean ) ; return root ; } var arr = [ 10 , 4 , 6 , 8 ] ; var n = arr . length ; document . write ( rmsValue ( arr , n ) . toFixed ( 5 ) ) ;

Index/key variables: i
Accumulator variables: i, square
Iterator variables: i
Javascript program:
const mod = ( 1e9 + 7 ) ; function power ( x , y , p ) { while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function check ( n ) { n -- ; let ans = n * n ; if ( ans >= mod ) ans %= mod ; ans += n + 2 ; if ( ans >= mod ) ans %= mod ; ans = ( power ( 2 , n , mod ) % mod * ans % mod ) % mod ; ans = ( ans - 1 + mod ) % mod ; return ans ; } let n = 4 ; document . write ( check ( n ) ) ;

Accumulator variables: ans, n
Javascript program:
function findLCM ( a , b ) { var lar = Math . max ( a , b ) ; var small = Math . min ( a , b ) ; for ( i = lar ; ; i += lar ) { if ( i % small == 0 ) return i ; } } var a = 5 , b = 7 ; document . write ( " " + a + " " + b + " " + findLCM ( a , b ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function primes ( n ) { var i = 2 ; var j = 0 ; var result = Array ( n ) var z = 0 ; while ( j < n ) { var flag = true ; for ( var item = 2 ; item <= parseInt ( i * 1 / 2 ) ; item ++ ) if ( i % item == 0 && i != item ) { flag = false ; break ; } if ( flag ) { result [ z ++ ] = i ; j += 1 ; } i += 1 ; } for ( i = 0 ; i < 5 ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) document . write ( result [ j ] ) ; document . write ( " " ) ; } } function smar_wln ( n ) { primes ( n ) ; } var n = 5 ; document . write ( " " + n + " " ) ; smar_wln ( n ) ;

Index/key variables: j
Accumulator variables: i, item, j, z
Iterator variables: i, item, j
Boolean variables: flag
Javascript program:
function SieveOfEratosthenes ( n , prime , primesquare , a ) { for ( var i = 2 ; i <= n ; i ++ ) prime [ i ] = true ; for ( var i = 0 ; i <= ( n * n + 1 ) ; i ++ ) primesquare [ i ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } var j = 0 ; for ( var p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] ) { a [ j ] = p ; primesquare [ p * p ] = true ; j ++ ; } } } function countDivisors ( n ) { if ( n == 1 ) return 1 ; var prime = Array ( n + 1 ) . fill ( false ) ; var primesquare = Array ( n * n + 1 ) . fill ( 0 ) ; SieveOfEratosthenes ( n , prime , primesquare , a ) ; var ans = 1 ; for ( var i = 0 ; ; i ++ ) { if ( a [ i ] * a [ i ] * a [ i ] > n ) break ; var cnt = 1 ; while ( n % a [ i ] == 0 ) { n = parseInt ( n / a [ i ] ) ; } ans = ans * cnt ; } if ( prime [ n ] ) ans = ans * 2 ; else if ( primesquare [ n ] ) ans = ans * 3 ; else if ( n != 1 ) ans = ans * 4 ; } function sumofFactors ( n ) { var res = 1 ; for ( var i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { var count = 0 , curr_sum = 1 ; var curr_term = 1 ; while ( n % i == 0 ) { count ++ ; n = parseInt ( n / i ) ; curr_term *= i ; curr_sum += curr_term ; } res *= curr_sum ; } if ( n >= 2 ) res *= ( 1 + n ) ; return res ; } function checkArithmetic ( n ) { var count = countDivisors ( n ) ; var sum = sumofFactors ( n ) ; return ( sum % count == 0 ) ; } var n = 6 ; ( checkArithmetic ( n ) ) ? ( document . write ( " " ) ) : ( document . write ( " " ) ) ;

Index/key variables: i, j, n, p
Accumulator variables: count, curr_sum, curr_term, i, j, p, res
Iterator variables: i, p
Javascript program:
function nextPower ( N , power ) { var carry = 0 ; for ( var i = 0 ; i < power . length ; i ++ ) { var prod = ( power [ i ] * N ) + carry ; power [ i ] = prod % 10 ; carry = parseInt ( prod / 10 ) ; } while ( carry >= 1 ) { power . push ( carry % 10 ) ; carry = parseInt ( carry / 10 ) ; } return power ; } function printPowerNumber ( X , N ) { var power = [ ] ; power . push ( 1 ) ; var res = [ ] ; for ( var i = 1 ; i <= X ; i ++ ) { power = nextPower ( N , power ) ; res . push ( power [ power . length - 1 ] ) ; res . push ( power [ 0 ] ) ; } for ( var i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] ) ; } var N = 19 , X = 4 ; printPowerNumber ( X , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function firstDigit ( n ) { let fact = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { fact = fact * i ; while ( fact % 10 == 0 ) fact = fact / 10 ; } while ( fact >= 10 ) fact = fact / 10 ; return ( Math . round ( fact ) ) ; } let n = 5 ; document . write ( firstDigit ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumofseries ( n ) { let res = 0 ; for ( let i = 1 ; i <= n ; i ++ ) res += ( i ) * ( i + 1 ) * ( i + 2 ) ; return res ; } document . write ( sumofseries ( 3 ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function printGMeans ( A , B , N ) { let R = Math . pow ( ( B / A ) , 1.0 / ( N + 1 ) ) ; for ( let i = 1 ; i <= N ; i ++ ) document . write ( A * Math . pow ( R , i ) + " " ) ; } let A = 3 , B = 81 , N = 2 ; printGMeans ( A , B , N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function digitSum ( n ) { let digSum = 0 ; while ( n > 0 ) { digSum += n % 10 ; n /= 10 ; } return digSum ; } function countInteger ( n , s ) { if ( n < s ) return 0 ; for ( let i = s ; i <= Math . min ( n , s + 163 ) ; i ++ ) if ( ( i - digitSum ( i ) ) > s ) return ( n - i + 1 ) ; return 0 ; } let n = 1000 , s = 100 ; document . write ( countInteger ( n , s ) ) ;

Accumulator variables: digSum, i, n
Iterator variables: i
Javascript program:
function division ( num1 , num2 ) { if ( num1 == 0 ) return 0 ; if ( num2 == 0 ) return Number . MAX_VALUE ; ; let negResult = false ; if ( num1 < 0 ) { num1 = - num1 ; if ( num2 < 0 ) num2 = - num2 ; else negResult = true ; } else if ( num2 < 0 ) { num2 = - num2 ; negResult = true ; } let quotient = 0 ; while ( num1 >= num2 ) { num1 = num1 - num2 ; quotient ++ ; } if ( negResult ) quotient = - quotient ; return quotient ; } let num1 = 13 , num2 = 2 ; document . write ( division ( num1 , num2 ) ) ;

Accumulator variables: quotient
Boolean variables: negResult
Javascript program:
function Nonagonal ( n ) { for ( let i = 1 ; i <= n ; i ++ ) { document . write ( parseInt ( i * ( 7 * i - 5 ) / 2 ) + " " ) ; } } let n = 10 ; Nonagonal ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function checkplusperfect ( x ) { let temp = x ; let n = 0 ; while ( x != 0 ) { x = parseInt ( x / 10 ) ; n ++ ; } x = temp ; let sum = 0 ; while ( x != 0 ) { sum += Math . pow ( x % 10 , n ) ; x = parseInt ( x / 10 ) ; } return ( sum == temp ) ; } let x = 9474 ; if ( checkplusperfect ( x ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: n, 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 twinPrime ( n1 , n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && Math . abs ( n1 - n2 ) == 2 ) ; } let n1 = 11 , n2 = 13 ; if ( twinPrime ( n1 , n2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Iterator variables: i
Javascript program:
function triangular_series ( n ) { let i , j = 1 , k = 1 ; for ( i = 1 ; i <= n ; i ++ ) { document . write ( k + " " ) ; j = j + 1 ; k = k + j ; } } let n = 5 ; triangular_series ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfSeries ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) for ( let j = 1 ; j <= i ; j ++ ) sum += j ; return sum ; } let n = 10 ; document . write ( sumOfSeries ( n ) ) ;

Accumulator variables: i, j, sum
Iterator variables: i, j