dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function convert_to_words ( num ) { let len = num . length ; if ( len == 0 len > 4 ) { return " " ; } let single_digits_temp = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let single_digits = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let two_digits = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let tens_multiple = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let tens_power = [ " " , " " ] ; let word = " " ; if ( len == 1 ) { word += single_digits [ num [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; return word ; } let i = 0 , ctr = 0 ; let s = " " ; while ( i < len ) { if ( len >= 3 ) { if ( num [ i ] != ' ' ) { word += single_digits_temp [ num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] + " " ; word += tens_power [ len - 3 ] + " " ; ctr ++ ; } len -- ; num = num . slice ( 1 , num . length ) ; } else { if ( ctr != 0 ) { s = " " ; word = word . substring ( 0 , word . length - 1 ) ; } if ( num [ i + 1 ] == ' ' ) if ( num [ i ] == ' ' ) word = word + " " ; else word += s + tens_multiple [ num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; else if ( num [ i ] == ' ' ) word += s + two_digits [ num [ i + 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ] ; else { if ( num [ i ] != ' ' ) word += s + tens_multiple [ num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] . substring ( 0 , tens_multiple [ num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] . length - 4 ) + " " ; else word += s ; word += single_digits [ num [ i + 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; } i += 2 ; } if ( i == len ) { if ( word . charAt ( 0 ) == ' ' ) word = word . substring ( 1 , word . length ) ; } } return word ; } function Aronsons_sequence ( n ) { let str = " " ; let ind = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . toLowerCase ( ) != str [ i ] . toUpperCase ( ) ) { ind += 1 ; } if ( str [ i ] == ' ' str [ i ] == ' ' ) { n -= 1 ; str += convert_to_words ( ( ind ) . toString ( ) . split ( " " ) ) + " " ; document . write ( ind + " " ) ; } if ( n == 0 ) break ; } } let n = 6 ; Aronsons_sequence ( n ) ;

Index/key variables: i
Accumulator variables: ctr, i, ind, len, n, str, word
Iterator variables: i
Javascript program:
function niceIndices ( A , n ) { var sum = 0 ; var m = new Map ( ) ; for ( var i = 0 ; i < n ; ++ i ) { if ( m . has ( A [ i ] ) ) m . set ( A [ i ] , m . get ( A [ i ] ) + 1 ) else m . set ( A [ i ] , 1 ) sum += A [ i ] ; } for ( var i = 0 ; i < n ; ++ i ) { var k = sum - A [ i ] ; if ( k % 2 == 0 ) { k = k >> 1 ; if ( m . has ( k ) ) { if ( ( A [ i ] == k && m . get ( k ) > 1 ) || ( A [ i ] != k ) ) document . write ( i + 1 + " " ) ; } } } } var A = [ 8 , 3 , 5 , 2 ] ; var n = A . length ; niceIndices ( A , n ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Javascript program:
function sumAP ( n , d ) { n = parseInt ( n / d ) ; return ( n ) * ( 1 + n ) * ( d / 2 ) ; } function sumMultiples ( n ) { n -- ; return sumAP ( n , 3 ) + sumAP ( n , 7 ) - sumAP ( n , 21 ) ; } let n = 24 ; document . write ( sumMultiples ( n ) ) ;

Accumulator variables: n
Javascript program:
function productSumDivisible ( n , size ) { var sum = 0 , product = 1 ; while ( n > 0 ) { if ( size % 2 == 0 ) { product *= n % 10 ; } else { sum += n % 10 ; } n = parseInt ( n / 10 ) ; size -- ; } if ( product % sum == 0 ) return true ; return false ; } var n = 1234 ; var len = 4 ; if ( productSumDivisible ( n , len ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: product, size, sum
Javascript program:
function productSumDivisible ( n ) { var sum = 0 var product = 1 var num = n . toString ( ) ; for ( i = 0 ; i < num . length ; i ++ ) { if ( i % 2 != 0 ) { product = product * Number ( num [ i ] ) } else { sum = sum + Number ( num [ i ] ) } } if ( product % sum == 0 ) { return true ; } else { return false ; } } var n = 1234 if ( productSumDivisible ( n ) ) { document . write ( " " ) } else { document . write ( " " ) }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function powGCD ( a , n , b ) { for ( i = 0 ; i < n ; i ++ ) a = a * a ; return gcd ( a , b ) ; } var a = 10 , b = 5 , n = 2 ; document . write ( powGCD ( a , n , b ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countDigit ( n ) { let temp = n ; let sum = 0 ; let product = 1 ; while ( temp != 0 ) { let d = temp % 10 ; temp = parseInt ( temp / 10 ) ; if ( d > 0 && n % d == 0 ) { sum += d ; product *= d ; } } document . write ( " " + sum ) ; document . write ( " " + product ) ; } let n = 1012 ; countDigit ( n ) ;

Accumulator variables: product, sum
Javascript program:
function isDivisiblePalindrome ( n ) { var hash = Array ( 10 ) . fill ( 0 ) ; var digitSum = 0 ; while ( n ) { digitSum += n % 10 ; hash [ n % 10 ] ++ ; n = parseInt ( n / 10 ) ; } if ( digitSum % 3 != 0 ) return false ; var oddCount = 0 ; for ( var i = 0 ; i < 10 ; i ++ ) { if ( hash [ i ] % 2 != 0 ) oddCount ++ ; } if ( oddCount > 1 ) return false ; else return true ; } var n = 34734 ; isDivisiblePalindrome ( n ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: digitSum, i, oddCount
Iterator variables: i
Javascript program:
function lcm ( a , b ) { return ( a * b ) / ( __gcd ( a , b ) ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function dfs ( src , adj , visited ) { visited [ src ] = true ; let count = 1 ; for ( let i = 0 ; i < adj [ src ] . length ; i ++ ) if ( ! visited [ adj [ src ] [ i ] ] ) count += dfs ( adj [ src ] [ i ] , adj , visited ) ; return count ; } function findMinTime ( arr , P , n ) { let adj = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) adj [ i ] = new Array ( ) ; for ( let i = 0 ; i < n ; i ++ ) { adj [ arr [ i ] ] . push ( P [ i ] ) ; } let visited = new Array ( n + 1 ) ; let ans = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { ans = lcm ( ans , dfs ( i , adj , visited ) ) ; } } return ans ; } let arr = [ 1 , 2 , 3 ] ; let P = [ 3 , 2 , 1 ] ; let n = arr . length ; document . write ( findMinTime ( arr , P , n ) ) ;

Index/key variables: i, src
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function productDivisible ( n , k ) { var product = 1 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 0 ) product *= n % 10 ; n = parseInt ( n / 10 ) ; position ++ ; } if ( product % k == 0 ) return true ; return false ; } var n = 321922 ; var k = 3 ; if ( productDivisible ( n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: position, product
Javascript program:
function productDivisible ( n , k ) { var product = 1 ; var num = n . toString ( ) for ( let i = 0 ; i < num . length ; i ++ ) { if ( i % 2 == 0 ) { product = product * Number ( num [ i ] ) } } if ( product % k == 0 ) { return true } else { return false ; } } var n = 321922 var k = 3 if ( productDivisible ( n , k ) ) { document . write ( " " ) } else { document . write ( " " ) }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { let fact = 1 ; for ( let i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } function npr ( n , r ) { let pnr = Math . floor ( factorial ( n ) / factorial ( n - r ) ) ; return pnr ; } function countPermutations ( n , r , k ) { return factorial ( k ) * ( r - k + 1 ) * npr ( n - k , r - k ) ; } let n = 8 ; let r = 5 ; let k = 2 ; document . write ( countPermutations ( n , r , k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factorial ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } function ncr ( n , r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } var m = 3 , n = 4 , k = 5 ; var totalTriangles = ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) ; document . write ( totalTriangles ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function SumDivisible ( n , k ) { let sum = 0 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 1 ) sum += n % 10 ; n = Math . floor ( n / 10 ) ; position ++ ; } if ( sum % k == 0 ) return true ; return false ; } let n = 592452 ; let k = 3 ; if ( SumDivisible ( n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: position, sum
Javascript program:
function sumDivisible ( n , k ) { var sum = 0 var num = n . toString ( ) for ( var i = 0 ; i < num . length ; i ++ ) { if ( i % 2 != 0 ) { sum = sum + Number ( num [ i ] ) } } if ( sum % k == 0 ) { return true ; } else { return false ; } } var n = 592452 var k = 3 if ( sumDivisible ( n , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findX ( n , k ) { let r = n ; let v = 0 ; let u = 0 ; let m = Math . floor ( Math . sqrt ( k ) + 1 ) ; for ( let i = 2 ; i <= m && k > 1 ; i ++ ) { if ( i == m ) { i = k ; } for ( let u = v = 0 ; k % i == 0 ; v ++ ) { k = Math . floor ( k / i ) ; } if ( v > 0 ) { let t = n ; while ( t > 0 ) { t = Math . floor ( t / i ) ; u += t ; } r = Math . min ( r , Math . floor ( u / v ) ) ; } } return r ; } let n = 5 ; let k = 2 ; document . write ( findX ( n , k ) ) ;

Accumulator variables: i, u, v
Iterator variables: i, u
Javascript program:
function fact ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) fact *= i ; return fact ; } function ncr ( n , r ) { var ncr = fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; return parseInt ( ncr ) ; } function ways ( m , w , n , k ) { var ans = 0 ; while ( m >= k ) { ans += ncr ( m , k ) * ncr ( w , n - k ) ; k += 1 ; } return parseInt ( ans ) ; } var m , w , n , k ; m = 7 ; w = 6 ; n = 5 ; k = 3 ; document . write ( ways ( m , w , n , k ) ) ;

Accumulator variables: ans, fact, i, k
Iterator variables: i
Javascript program:
let MAX = 1000000 ; let prime = new Array ( MAX + 1 ) ; function SieveOfEratosthenes ( ) { prime . fill ( true ) 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 productOfKthPrimes ( arr , n , k ) { let c = 0 ; let product = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { c ++ ; if ( c % k == 0 ) { product *= arr [ i ] ; c = 0 ; } } } document . write ( product + " " ) ; } SieveOfEratosthenes ( ) ; let n = 5 , k = 2 ; let arr = [ 2 , 3 , 5 , 7 , 11 ] ; productOfKthPrimes ( arr , n , k ) ;

Index/key variables: i, p
Accumulator variables: c, i, p, product
Iterator variables: i, p
Javascript program:
function countBits ( n ) { var count = 0 ; while ( n ) { count ++ ; n >>= 1 ; } return count ; } var n = 32 ; document . write ( " " + countBits ( n ) ) ;

Accumulator variables: count
Javascript program:
function OddDivCount ( a , b ) { let res = 0 ; for ( let i = a ; i <= b ; ++ i ) { let divCount = 0 ; for ( let j = 1 ; j <= i ; ++ j ) { if ( i % j == 0 ) { ++ divCount ; } } if ( ( divCount % 2 ) != 0 ) { ++ res ; } } return res ; } let a = 1 , b = 10 ; document . write ( OddDivCount ( a , b ) ) ;

Iterator variables: i, j
Javascript program:
function largestSquareFactor ( num ) { let answer = 1 ; for ( let i = 2 ; i < Math . sqrt ( num ) ; ++ i ) { let cnt = 0 ; let j = i ; while ( num % j == 0 ) { cnt ++ ; j *= i ; } if ( cnt & 1 ) { cnt -- ; answer *= Math . pow ( i , cnt ) ; } else { answer *= Math . pow ( i , cnt ) ; } } return answer ; } let N = 420 ; document . write ( largestSquareFactor ( N ) ) ;

Accumulator variables: answer, cnt, j
Iterator variables: i
Javascript program:
function calculateDifference ( arr , n ) { var max_val = Math . max . apply ( Math , arr ) ; var prime = Array ( max_val + 1 ) . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } var P1 = 1 , P2 = 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { P1 *= arr [ i ] ; } else if ( arr [ i ] != 1 ) { P2 *= arr [ i ] ; } } return Math . abs ( P2 - P1 ) ; } var arr = [ 1 , 3 , 5 , 10 , 15 , 7 ] ; var n = arr . length ; document . write ( calculateDifference ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: P1, P2, i, p
Iterator variables: i, p
Javascript program:
function EqualNumbers ( a , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += a [ i ] ; if ( sum % n ) return n - 1 ; return n ; } let a = [ 1 , 4 , 1 ] ; let n = a . length ; document . write ( EqualNumbers ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function count_odd_pair ( n , a ) { var odd = 0 , even = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } var ans = odd * even * 2 ; return ans ; } function count_even_pair ( odd_sum_pairs , n ) { var total_pairs = ( n * ( n - 1 ) ) ; var ans = total_pairs - odd_sum_pairs ; return ans ; } var n = 6 ; var a = [ 2 , 4 , 5 , 9 , 1 , 8 ] ; var odd_sum_pairs = count_odd_pair ( n , a ) ; var even_sum_pairs = count_even_pair ( odd_sum_pairs , n ) ; document . write ( " " + even_sum_pairs + " " ) ; document . write ( " " + odd_sum_pairs + " " ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function findSteps ( n , m , a ) { var cur = 1 ; var steps = 0 ; for ( var i = 0 ; i < m ; i ++ ) { if ( a [ i ] >= cur ) steps += ( a [ i ] - cur ) ; else steps += ( n - cur + a [ i ] ) ; cur = a [ i ] ; } return steps ; } var n = 3 , m = 3 ; var a = [ 2 , 1 , 2 ] ; document . write ( findSteps ( n , m , a ) ) ;

Index/key variables: i
Accumulator variables: i, steps
Iterator variables: i
Javascript program:
function isPowerOfTwo ( x ) { return ( x > 0 && ( ! ( ( x & ( x - 1 ) ) > 0 ) ) ) ; } function Count_pairs ( a , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) ) count ++ ; } let ans = ( count * ( count - 1 ) ) / 2 ; document . write ( ans ) ; } let a = [ 2 , 5 , 8 , 16 , 128 ] ; let n = a . length ; Count_pairs ( a , n ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function factorial ( n ) { let result = 1 ; for ( let i = 1 ; i <= n ; i ++ ) result = result * i ; return result ; } function nCr ( n , r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } function calculate_result ( n ) { let result = 2 * nCr ( ( n - 2 ) , ( n / 2 - 1 ) ) ; return result ; } let a = 2 ; let b = 4 ; document . write ( calculate_result ( 2 * a ) + " " ) ; document . write ( calculate_result ( 2 * b ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function PossibleValues ( b , x , n ) { let leastdivisible = ( Math . floor ( b / x ) + 1 ) * x ; let flag = 1 ; while ( leastdivisible <= n ) { if ( leastdivisible - b >= 1 ) { document . write ( leastdivisible - b + " " ) ; leastdivisible += x ; flag = 0 ; } else break ; } if ( flag > 0 ) document . write ( - 1 + " " ) ; } let b = 10 , x = 6 , n = 40 ; PossibleValues ( b , x , n ) ;

Accumulator variables: leastdivisible
Javascript program:
function digitProduct ( digits , start , end ) { let pro = 1 ; for ( let i = start ; i <= end ; i ++ ) { pro *= digits [ i ] ; } return pro ; } function isDistinct ( N ) { let s = " " ; let len = s . length ; let digits = new Array ( ) ; let products = new Array ( ) ; for ( let i = 0 ; i < len ; i ++ ) { digits [ i ] = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } for ( let i = 0 ; i < len ; i ++ ) { for ( let j = i ; j < len ; j ++ ) { let val = digitProduct ( digits , i , j ) ; if ( products . includes ( val ) ) return false ; else products . push ( val ) ; } } return true ; } let N = 324 ; if ( isDistinct ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i, j, pro
Iterator variables: i, j
Javascript program:
function get_last_two_digit ( N ) { if ( N <= 10 ) { let ans = 0 , fac = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { fac = fac * i ; ans += fac ; } return ans % 100 ; } return 13 ; } let N = 1 ; for ( N = 1 ; N <= 10 ; N ++ ) document . write ( " " + N + " " + get_last_two_digit ( N ) + " " ) ;

Accumulator variables: N, ans, i
Iterator variables: N, i
Javascript program:
function isProductEven ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & 1 ) == 0 ) return true ; return false ; } let arr = [ 2 , 4 , 3 , 5 ] ; let n = arr . length ; if ( isProductEven ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateSquareSum ( n ) { if ( n <= 0 ) return 0 ; var fibo = Array ( n + 1 ) . fill ( 0 ) ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; var sum = ( fibo [ 0 ] * fibo [ 0 ] ) + ( fibo [ 1 ] * fibo [ 1 ] ) ; for ( i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += ( fibo [ i ] * fibo [ i ] ) ; } return sum ; } var n = 6 ; document . write ( " " + calculateSquareSum ( n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function MinimumMoves ( a , n , x ) { var ans = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { var p = parseInt ( ( a [ i - 1 ] - a [ i ] ) / x + 1 ) ; ans += p ; a [ i ] += p * x ; } } return ans ; } var arr = [ 1 , 3 , 3 , 2 ] ; var x = 2 ; var n = arr . length ; document . write ( MinimumMoves ( arr , n , x ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function SumOfDigits ( str , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += ( str . charAt ( i ) - ' ' ) ; return sum ; } function Divisible ( str , n ) { if ( SumOfDigits ( str , n ) % 3 == 0 && str . charAt ( n - 1 ) == ' ' ) return true ; return false ; } var str = " " ; var n = str . length ; if ( Divisible ( str , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPrime ( k ) { if ( k <= 1 ) return false ; for ( let i = 2 ; i < k ; i ++ ) if ( k % i == 0 ) return false ; return true ; } function check ( num , k ) { let flag = 1 ; for ( let i = 2 ; i < k ; i ++ ) { if ( num % i == 0 ) flag = 0 ; } if ( flag == 1 ) { if ( num % k == 0 ) return 1 ; else return 0 ; } else return 0 ; } function findCount ( a , b , k ) { let count = 0 ; if ( ! isPrime ( k ) ) return 0 ; else { let ans ; for ( let i = a ; i <= b ; i ++ ) { ans = check ( i , k ) ; if ( ans == 1 ) count ++ ; else continue ; } } return count ; } let a = 2020 , b = 6300 , k = 29 ; document . write ( findCount ( a , b , k ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findkth ( n , k ) { let v1 = [ ] ; let v2 = [ ] ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . push ( i ) ; if ( i != Math . sqrt ( n ) ) v2 . push ( n / i ) ; } } v2 . reverse ( ) ; if ( k > ( v1 . length + v2 . length ) ) document . write ( " " ) ; else { if ( k <= v1 . length ) document . write ( v1 [ k - 1 ] ) ; else document . write ( v2 [ k - v1 . length - 1 ] ) ; } } let n = 15 , k = 2 ; findkth ( n , k ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function NumberOfSolutions ( a , b , c , d ) { let ans = 0 ; for ( let i = a ; i <= b ; i ++ ) if ( d >= Math . max ( c , i + 1 ) ) ans += d - Math . max ( c , i + 1 ) + 1 ; return ans ; } let a = 2 , b = 3 , c = 3 , d = 4 ; document . write ( NumberOfSolutions ( a , b , c , d ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findF_N ( n ) { var ans = 0 ; for ( var i = 0 ; i < n ; ++ i ) ans += ( i + 1 ) * ( n - i - 1 ) ; return ans ; } var n = 3 ; document . write ( findF_N ( n ) ) ;

Accumulator variables: ans
Iterator variables: i
Javascript program:
function findNumber ( n , d ) { let ans = " " ; if ( d != 10 ) { ans += ( d ) . toString ( ) ; for ( let i = 1 ; i < n ; i ++ ) ans += ' ' ; } else { if ( n == 1 ) ans += " " ; else { ans += ' ' ; for ( let i = 1 ; i < n ; i ++ ) ans += ' ' ; } } return ans ; } let n = 12 , d = 3 ; document . write ( findNumber ( n , d ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
var MAX = 1000000 ; var sieve_Prime = Array . from ( { length : MAX + 4 } , ( _ , i ) => 0 ) ; var sieve_count = Array . from ( { length : MAX + 4 } , ( _ , i ) => 0 ) ; function form_sieve ( ) { sieve_Prime [ 1 ] = 1 ; for ( i = 2 ; i <= MAX ; i ++ ) { if ( sieve_Prime [ i ] == 0 ) { for ( j = i * 2 ; j <= MAX ; j += i ) { if ( sieve_Prime [ j ] == 0 ) { sieve_Prime [ j ] = 1 ; sieve_count [ i ] ++ ; } } } } } form_sieve ( ) ; var n = 2 ; document . write ( " " + ( sieve_count [ n ] + 1 ) ) ; n = 3 ; document . write ( " " + ( sieve_count [ n ] + 1 ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let matrix = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { matrix [ i ] = new Array ( 5 ) ; for ( let j = 0 ; j < 5 ; j ++ ) { matrix [ i ] [ j ] = 0 ; } } let row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } document . write ( " " ) ; } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) == size - 1 ) document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } }

Index/key variables: column_index, i, j, row_index
Accumulator variables: column_index, i, j, row_index
Iterator variables: column_index, i, j, row_index
Javascript program:
let matrix = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { matrix [ i ] = new Array ( 5 ) ; } let row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { document . write ( " " , matrix [ row_index ] [ column_index ] ) ; } document . write ( " " ) ; } document . write ( " " + " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) < size - 1 ) document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } }

Index/key variables: column_index, i, row_index
Accumulator variables: column_index, i, row_index
Iterator variables: column_index, i, row_index
Javascript program:
function PrimeFactors ( n ) { let v = [ ] ; let x = n ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( x % i == 0 ) { v . push ( i ) ; while ( x % i == 0 ) x = Math . floor ( x / i ) ; } } if ( x > 1 ) v . push ( x ) ; return v ; } function GoodNumber ( n ) { let v = PrimeFactors ( n ) ; let ans = 1 ; for ( let i = 0 ; i < v . length ; i ++ ) ans *= v [ i ] ; return ans ; } let n = 12 ; document . write ( GoodNumber ( n ) ) ;

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