codeparrot/xlcost-text-to-code huggingface dataset:
Construct an array from its pair | Utility function to print the array ; Function to generate the original array from the pair - product array ; First element of the resulting array ; Find all the other elements ; Print the elements of the generated array ; Driver code
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function constructArr ( pair , n ) { let size = Math . floor ( ( 1 + Math . sqrt ( 1 + 8 * n ) ) / 2 ) ; let arr = new Array ( size ) ; arr [ 0 ] = Math . floor ( Math . sqrt ( ( pair [ 0 ] * pair [ 1 ] ) / pair [ size - 1 ] ) ) ; for ( let i = 1 ; i < size ; i ++ ) arr [ i ] = Math . floor ( pair [ i - 1 ] / arr [ 0 ] ) ; printArr ( arr , size ) ; } let pair = [ 48 , 18 , 24 , 24 , 32 , 12 ] ; let n = pair . length ; constructArr ( pair , n ) ;
Count of odd and even sum pairs in an array | Function to find the count of pairs with odd sum and the count of pairs with even sum ; To store the count of even and odd number from the array ; If the current element is even ; If it is odd ; To store the count of pairs with even sum ; All the even elements will make pairs with each other and the sum of the pair will be even ; All the odd elements will make pairs with each other and the sum of the pair will be even ; To store the count of pairs with odd sum ; All the even elements will make pairs with all the odd element and the sum of the pair will be odd ; Driver code
function findPairs ( arr , n ) { let cntEven = 0 , cntOdd = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) cntEven ++ ; else cntOdd ++ ; } let evenPairs = 0 ; evenPairs += ( ( cntEven * ( cntEven - 1 ) ) / 2 ) ; evenPairs += ( ( cntOdd * ( cntOdd - 1 ) ) / 2 ) ; let oddPairs = 0 ; oddPairs += ( cntEven * cntOdd ) ; document . write ( " " + oddPairs + " " ) ; document . write ( " " + evenPairs ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; findPairs ( arr , n ) ;
Number of ways to distribute N Paper Set among M students | javascript implementation of the approach ; Function to return n ! % 1000000007 ; To store the factorial ; Find the factorial ; Function to return the count of possible ways ; Driver code
MOD = 1000000007 ; function factMod ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) { fact *= ( i % MOD ) ; fact %= MOD ; } return parseInt ( fact ) ; } function countWays ( n , m ) { return factMod ( m ) ; } var n = 2 , m = 2 ; document . write ( countWays ( n , m ) ) ;
Program for nth Fuss – Catalan Number | Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth FussCatalan number in O ( n ) time ; Calculate value of 3 nCn ; return 3 nCn / ( 2 n + 1 ) ; Driver code
function binomialCoeff ( n , k ) { var res = 1 ; if ( k > n - k ) k = n - k ; for ( var i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res = parseInt ( res / ( i + 1 ) ) ; } return res ; } function Fuss_catalan ( n ) { var c = binomialCoeff ( 3 * n , n ) ; return parseInt ( c / ( 2 * n + 1 ) ) ; } for ( var i = 0 ; i < 10 ; i ++ ) document . write ( Fuss_catalan ( i ) + " " ) ;
Check if a number is Euler Pseudoprime | Function that returns true if n is composite ; Check if there is any divisor of n . we only need check divisor till sqrt ( n ) because if there is divisor which is greater than sqrt ( n ) then there must be a divisor which is less than sqrt ( n ) ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is greater than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Function that returns true if N is Euler Pseudoprime to the base A ; Invalid base ; N is not a composite odd number ; If A and N are not coprime ; All the conditions for Euler Pseudoprime are satisfied ; Driver code
function isComposite ( n ) { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return true ; } return false ; } 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 __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function isEulerPseudoprime ( N , A ) { if ( A <= 0 ) return false ; if ( N % 2 == 0 || ! isComposite ( N ) ) return false ; if ( __gcd ( A , N ) != 1 ) return false ; let mod = Power ( A , ( N - 1 ) / 2 , N ) ; if ( mod != 1 && mod != N - 1 ) return false ; return true ; } let N = 121 , A = 3 ; if ( isEulerPseudoprime ( N , A ) ) document . write ( " " ) ; else document . write ( " " ) ;
Minimum difference between any two primes from the given range | Javascript implementation of the approach ; Function for Sieve of Eratosthenes ; Function to return the minimum difference between any two prime numbers from the given range [ L , R ] ; Find the first prime from the range ; Find the second prime from the range ; If the number of primes in the given range is < 2 ; To store the minimum difference between two consecutive primes from the range ; Range left to check for primes ; For every integer in the range ; If the current integer is prime ; If the difference between i and snd is minimum so far ; Generate primes
const sz = 1e5 ; let isPrime = new Array ( sz + 1 ) ; function sieve ( ) { isPrime . fill ( true ) ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( let j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } function minDifference ( L , R ) { let fst = 0 ; for ( let i = L ; i <= R ; i ++ ) { if ( isPrime [ i ] ) { fst = i ; break ; } } let snd = 0 ; for ( let i = fst + 1 ; i <= R ; i ++ ) { if ( isPrime [ i ] ) { snd = i ; break ; } } if ( snd == 0 ) return - 1 ; let diff = snd - fst ; let left = snd + 1 ; let right = R ; for ( let i = left ; i <= right ; i ++ ) { if ( isPrime [ i ] ) { if ( i - snd <= diff ) { fst = snd ; snd = i ; diff = snd - fst ; } } } return diff ; } sieve ( ) ; let L = 21 , R = 50 ; document . write ( minDifference ( L , R ) ) ;
Number of non | Function to return the required count ; To store the final result ; Two pointer loop ; Initialising j ; Looping till the subarray increases ; Update ret ; Update i ; Return ret ; Driver code
function findCnt ( arr , n , k ) { var ret = 0 ; var i = 0 ; while ( i < n ) { var j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; var x = Math . max ( 0 , j - i - k + 1 ) ; ret += ( x * ( x + 1 ) ) / 2 ; i = j ; } return ret ; } var arr = [ 5 , 4 , 3 , 2 , 1 ] ; var n = arr . length ; var k = 2 ; document . write ( findCnt ( arr , n , k ) ) ;
Count of elements which are second smallest among three consecutive elements | Function to return the count of elements P [ i ] such that P [ i ] is the second smallest among P [ i - 1 ] , P [ i ] and P [ i + 1 ] ; To store the required answer ; Traverse from the second element to the second last element ; Return the required answer ; Driver code
function countElements ( p , n ) { var ans = 0 ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( p [ i - 1 ] > p [ i ] && p [ i ] > p [ i + 1 ] ) ans ++ ; else if ( p [ i - 1 ] < p [ i ] && p [ i ] < p [ i + 1 ] ) ans ++ ; } return ans ; } var p = [ 2 , 5 , 1 , 3 , 4 ] ; var n = p . length ; document . write ( countElements ( p , n ) ) ;
Count integers in the range [ A , B ] that are not divisible by C and D | Function to return the count of integers from the range [ a , b ] that are not divisible by c and d ; Numbers which are divisible by c ; Numbers which are divisible by d ; Find lowest common factor of c and d ; Numbers which are divisible by both c and d ; Return the required answer ; Driver code
function countNums ( a , b , c , d ) { let x = parseInt ( b / c ) - parseInt ( ( a - 1 ) / c ) ; let y = parseInt ( b / d ) - parseInt ( ( a - 1 ) / d ) ; let k = parseInt ( ( c * d ) / __gcd ( c , d ) ) ; let z = parseInt ( b / k ) - parseInt ( ( a - 1 ) / k ) ; return b - a + 1 - x - y + z ; } function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } let a = 10 , b = 50 , c = 4 , d = 6 ; document . write ( countNums ( a , b , c , d ) ) ;
Number of non | Function to return the count of increasing subarrays of length k ; To store the final result ; Two pointer loop ; Initialising j ; Looping till the subarray increases ; Updating the required count ; Updating i ; Returning res ; Driver code
function cntSubArrays ( arr , n , k ) { var res = 0 ; var i = 0 ; while ( i < n ) { var j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; res += Math . max ( j - i - k + 1 , 0 ) ; i = j ; } return res ; } var arr = [ 1 , 2 , 3 , 2 , 5 ] ; var n = arr . length ; var k = 2 ; document . write ( cntSubArrays ( arr , n , k ) ) ;
Longest sub | Function to return the length of the largest subsequence with minimum possible LCM ; Minimum value from the array ; To store the frequency of the minimum element in the array ; If current element is equal to the minimum element ; Driver code
function maxLen ( arr , n ) { var min_val = arr . reduce ( ( a , b ) => Math . min ( a , b ) ) var freq = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == min_val ) freq ++ ; } return freq ; } var arr = [ 1 , 3 , 1 ] ; var n = arr . length ; document . write ( maxLen ( arr , n ) ) ;
Program to find the last digit of X in base Y | Function to find the last digit of X in base Y ; Driver code
function last_digit ( X , Y ) { document . write ( X % Y ) ; } var X = 55 , Y = 3 ; last_digit ( X , Y ) ;
Count of squares that can be drawn without lifting the pencil | Function to return the count of squares that can be formed ; Driver code
function countSquares ( n ) { return ( Math . pow ( n , 2 ) - ( 2 * n ) + 2 ) ; } var n = 2 ; document . write ( countSquares ( n ) ) ;
Integer part of the geometric mean of the divisors of N | Function to return the integer part of the geometric mean of the divisors of n ; Driver code
function geometricMean ( n ) { return Math . sqrt ( n ) ; } var n = 16 ; document . write ( geometricMean ( n ) ) ;
Number of K 's such that the given array can be divided into two sets satisfying the given conditions | Function to return the count of K 's  such that the array can be divided  into two sets containing equal number  of elements when all the elements less  than K are in one set and the rest  of the elements are in the other set ; Sort the given array ; Return number of such Ks ; Driver code
function two_sets ( a , n ) { a . sort ( ) ; return a [ n / 2 ] - a [ ( n / 2 ) - 1 ] ; } var a = [ 1 , 4 , 4 , 6 , 7 , 9 ] ; var n = a . length ; document . write ( two_sets ( a , n ) ) ;
Count of pairs in an array such that the highest power of 2 that divides their product is 1 | Function to return the count of valid pairs ; To store the count of odd numbers and the count of even numbers such that 2 is the only even factor of that number ; If current number is odd ; If current number is even and 2 is the only even factor of it ; Calculate total number of valid pairs ; Driver code
function cntPairs ( a , n ) { var odd = 0 , even = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) odd ++ ; else if ( ( a [ i ] / 2 ) % 2 == 1 ) even ++ ; } var ans = odd * even + ( odd * ( odd - 1 ) ) / 2 ; return ans ; } var a = [ 4 , 2 , 7 , 11 , 14 , 15 , 18 ] ; var n = a . length ; document . write ( cntPairs ( a , n ) ) ;
Make the array non | Function to make array non - decreasing ; Take the first element ; Perform the operation ; Traverse the array ; Next element ; If next element is greater than the current element then decrease it to increase the possibilities ; It is not possible to make the array non - decreasing with the given operation ; Next element is now the current ; The array can be made non - decreasing with the given operation ; Driver Code
function isPossible ( a , n ) { var cur = a [ 0 ] ; cur -- ; for ( var i = 1 ; i < n ; i ++ ) { var nxt = a [ i ] ; if ( nxt > cur ) nxt -- ; else if ( nxt < cur ) return false ; cur = nxt ; } return true ; } var a = [ 1 , 2 , 1 , 2 , 3 ] ; var n = a . length ; if ( isPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find the maximum element in the array other than Ai | Function to find maximum element among ( N - 1 ) elements other than a [ i ] for each i from 1 to N ; To store prefix max element ; To store suffix max element ; Find the maximum element in the array other than a [ i ] ; Driver code
function max_element ( a , n ) { let pre = new Array ( n ) ; pre [ 0 ] = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) pre [ i ] = Math . max ( pre [ i - 1 ] , a [ i ] ) ; let suf = new Array ( n ) ; suf [ n - 1 ] = a [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) suf [ i ] = Math . max ( suf [ i + 1 ] , a [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i == 0 ) document . write ( suf [ i + 1 ] + " " ) ; else if ( i == n - 1 ) document . write ( pre [ i - 1 ] + " " ) ; else document . write ( Math . max ( pre [ i - 1 ] , suf [ i + 1 ] ) + " " ) ; } } let a = [ 2 , 5 , 6 , 1 , 3 ] ; let n = a . length ; max_element ( a , n ) ;
Find the Kth position element of the given sequence | Function to return the kth number from the required sequence ; Count of odd integers in the sequence ; kth number is even ; It is odd ; Driver code
function kthNum ( n , k ) { var a = ( n + 1 ) / 2 ; if ( k > a ) return ( 2 * ( k - a ) ) ; return ( 2 * k - 1 ) ; } var n = 7 , k = 7 ; document . write ( kthNum ( n , k ) ) ;
Find K such that | A | Function to find k such that | a - k | = | b - k | ; If ( a + b ) is even ; Driver code
function find_k ( a , b ) { if ( ( a + b ) % 2 == 0 ) return ( ( a + b ) / 2 ) ; return - 1 ; } var a = 2 , b = 16 ; document . write ( find_k ( a , b ) ) ;
Increasing permutation of first N natural numbers | Function that returns true if it is possible to make the permutation increasing by swapping any two numbers ; To count misplaced elements ; Count all misplaced elements ; If possible ; Driver code
function isPossible ( a , n ) { let k = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] != i + 1 ) k ++ ; } if ( k <= 2 ) return true ; return false ; } let a = [ 5 , 2 , 3 , 4 , 1 ] ; let n = a . length ; if ( isPossible ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find the number of positive integers less than or equal to N that have an odd number of digits | Function to return the number of positive integers less than or equal to N that have odd number of digits ; Driver code
function odd_digits ( n ) { if ( n < 10 ) return n ; else if ( n / 10 < 10 ) return 9 ; else if ( n / 100 < 10 ) return 9 + n - 99 ; else if ( n / 1000 < 10 ) return 9 + 900 ; else if ( n / 10000 < 10 ) return 909 + n - 9999 ; else return 90909 ; } let n = 893 ; document . write ( odd_digits ( n ) ) ;
Count of N | Function to return the count of N - digit palindrome numbers ; Driver code
function nDigitPalindromes ( n ) { return ( 9 * Math . pow ( 10 , parseInt ( ( n - 1 ) / 2 ) ) ) ; } var n = 2 ; document . write ( nDigitPalindromes ( n ) ) ;
Maximum LCM among all pairs ( i , j ) of first N natural numbers | Function to return the maximum LCM among all the pairs ( i , j ) of first n natural numbers ; Driver code
function maxLCM ( n ) { return ( n * ( n - 1 ) ) ; } var n = 3 ; document . write ( maxLCM ( n ) ) ;
Sum of all the numbers in the Nth row of the given triangle | Function to return the sum of the nth row elements of the given triangle ; Driver code
function getSum ( n ) { return ( ( n - 1 ) + Math . pow ( n , 2 ) ) ; } var n = 3 ; document . write ( getSum ( n ) ) ;
Number of edges in a perfect binary tree with N levels | Function to return the count of edges in an n - level perfect binary tree ; Driver code
function cntEdges ( n ) { var edges = Math . pow ( 2 , n ) - 2 ; return edges ; } var n = 4 ; document . write ( cntEdges ( n ) ) ;
Number of cells in the Nth order figure | Function to return the number of cells in the nth order figure of the given type ; Driver code
function cntCells ( n ) { var cells = Math . pow ( n , 2 ) + Math . pow ( n - 1 , 2 ) ; return cells ; } var n = 3 ; document . write ( cntCells ( n ) ) ;
Sum of all the numbers in the Nth parenthesis | Function to return the sum of the numbers in the nth parenthesis ; Driver code
function findSum ( n ) { return Math . pow ( n , 3 ) ; } var n = 3 ; document . write ( findSum ( n ) ) ;
Find the count of natural Hexadecimal numbers of size N | Function to return the count of n - digit natural hexadecimal numbers ; Driver code
function count ( n ) { return 15 * Math . pow ( 16 , n - 1 ) ; } var n = 2 ; document . write ( count ( n ) ) ;
Largest Even and Odd N | Function to print the largest n - digit even and odd numbers in octal number system ; Append '7' ( N - 1 ) times ; Append '6' for an even number ; Append '7' for an odd number ; Driver code
function findNumbers ( n ) { var ans = " " ; for ( var i = 0 ; i < n - 1 ; i ++ ) ans += ' ' ; var even = ans + ' ' ; var odd = ans + ' ' ; document . write ( " " + even + " " ) ; document . write ( " " + odd + " " ) ; } var n = 4 ; findNumbers ( n ) ;
Nth term of a Custom Fibonacci series | Function to return the nth term of the required sequence ; Driver code
function nth_term ( a , b , n ) { var z = 0 ; if ( n % 6 == 1 ) z = a ; else if ( n % 6 == 2 ) z = b ; else if ( n % 6 == 3 ) z = b - a ; else if ( n % 6 == 4 ) z = - a ; else if ( n % 6 == 5 ) z = - b ; if ( n % 6 == 0 ) z = - ( b - a ) ; return z ; } var a = 10 , b = 17 , n = 3 ; document . write ( nth_term ( a , b , n ) ) ;
Check whether the given integers a , b , c and d are in proportion | Function that returns true if the given four integers are in proportion ; Array will consist of only four integers ; Sort the array ; Find the product of extremes and means ; If the products are equal ; Driver code
function inProportion ( arr ) { var n = 4 ; arr . sort ( ) ; var extremes = arr [ 0 ] * arr [ 3 ] ; var means = arr [ 1 ] * arr [ 2 ] ; if ( extremes == means ) return true ; return false ; } var arr = [ 1 , 2 , 4 , 2 ] if ( inProportion ( arr ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find the deleted value from the array when average of original elements is given | Function to return the missing element ; Find the sum of the array elements ; The numerator and the denominator of the equation ; If not divisible then X is not an integer it is a floating point number ; Return X ; Driver code
function findMissing ( arr , n , k , avg ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } var num = ( avg * ( n + k ) ) - sum ; var den = k ; if ( num % den != 0 ) return - 1 ; return ( Math . floor ( num / den ) ) ; } var k = 3 ; var avg = 4 ; var arr = [ 2 , 7 , 3 ] ; var n = arr . length ; document . write ( findMissing ( arr , n , k , avg ) ) ;
Count of N | Function to return the factorial of n ; Function to return the count of n - digit numbers with all distinct digits ; Driver code
function factorial ( n ) { if ( n == 0 ) return 1 ; return n * factorial ( n - 1 ) ; } function countNum ( n ) { if ( n > 10 ) return 0 ; return ( 9 * factorial ( 9 ) / factorial ( 10 - n ) ) ; } var n = 3 ; document . write ( countNum ( n ) ) ;
Maximum number of distinct positive integers that can be used to represent N | Function to return the required count ; Driver code
function count ( n ) { return parseInt ( ( - 1 + Math . sqrt ( 1 + 8 * n ) ) / 2 ) ; } var n = 10 ; document . write ( count ( n ) ) ;
Find the previous fibonacci number | Function to return the previous fibonacci number ; Driver code
function previousFibonacci ( n ) { var a = n / ( ( 1 + Math . sqrt ( 5 ) ) / 2 ) ; return Math . round ( a ) ; } var n = 8 ; document . write ( previousFibonacci ( n ) ) ;
Find the quadratic equation from the given roots | Function to find the quadratic equation whose roots are a and b ; Driver Code
function findEquation ( a , b ) { var sum = ( a + b ) ; var product = ( a * b ) ; document . write ( " " + sum + " " + product + " " ) ; } var a = 2 , b = 3 ; findEquation ( a , b ) ;
Smallest N digit number which is a perfect fourth power | Function to return the smallest n - digit number which is a perfect fourth power ; Driver code
function cal ( n ) { var res = Math . pow ( Math . ceil ( ( Math . pow ( Math . pow ( 10 , ( n - 1 ) ) , 1 / 4 ) ) ) , 4 ) ; return parseInt ( res ) ; } var n = 1 ; document . write ( cal ( n ) ) ;
Count of 0 s in an N | Function to return the count of 0 s in an n - level hexagon ; Driver code
function count ( n ) { return 3 * n * ( n - 1 ) + 1 ; } var n = 3 ; document . write ( count ( n ) ) ;
Number of words that can be made using exactly P consonants and Q vowels from the given string | Function to return the value of nCk ; Function to return the factorial of n ; Function that returns true if ch is a vowel ; Function to return the number of words possible ; To store the count of vowels and consonanats in the given string ; If current character is a vowel ; Find the total possible words ; Driver code
function binomialCoeff ( n , k ) { if ( k == 0 k == n ) return 1 ; return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ; } function fact ( n ) { if ( n >= 1 ) return n * fact ( n - 1 ) ; else return 1 ; } function isVowel ( ch ) { if ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) { return true ; } return false ; } function countWords ( s , p , q ) { var countc = 0 , countv = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) countv ++ ; else countc ++ ; } var a = binomialCoeff ( countc , p ) ; var b = binomialCoeff ( countv , q ) ; var c = fact ( p + q ) ; var ans = ( a * b ) * c ; return ans ; } var s = " " ; var p = 4 , q = 3 ; document . write ( countWords ( s , p , q ) ) ;
Count of elements on the left which are divisible by current element | Utility function to print the elements of the array ; Function to generate and print the required array ; For every element of the array ; To store the count of elements on the left that the current element divides ; Print the generated array ; Driver code
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function generateArr ( A , n ) { let B = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let cnt = 0 ; for ( let j = 0 ; j < i ; j ++ ) { if ( A [ j ] % A [ i ] == 0 ) cnt ++ ; } B [ i ] = cnt ; } printArr ( B , n ) ; } let A = [ 3 , 5 , 1 ] ; let n = A . length ; generateArr ( A , n ) ;
Represent the given number as the sum of two composite numbers | Function to find two composite numbers which when added give sum as n ; Only 8 and 10 can be represented as the sum of two composite integers ; If n is even ; If n is odd ; Driver code
function findNums ( n ) { if ( n <= 11 ) { if ( n == 8 ) document . write ( " " ) ; if ( n == 10 ) document . write ( " " ) ; else document . write ( " " ) ; return ; } if ( n % 2 == 0 ) document . write ( " " + ( n - 4 ) ) ; else document . write ( " " + ( n - 9 ) ) ; } var n = 13 ; findNums ( n ) ;
Count of N | Function to return the count of possible numbers ; Driver code
function count ( n ) { return Math . pow ( 2 , n - 1 ) ; } var n = 4 ; document . write ( count ( n ) ) ;
Find the next fibonacci number | Function to return the next fibonacci number ; Driver code
function nextFibonacci ( n ) { let a = n * ( 1 + Math . sqrt ( 5 ) ) / 2.0 ; return Math . round ( a ) ; } let n = 5 ; document . write ( nextFibonacci ( n ) ) ;
Sum of all the numbers present at given level in Pascal 's triangle | Function to find sum of numbers at Lth level in Pascals Triangle ; Driver Code
function sum ( h ) { return Math . pow ( 2 , h - 1 ) ; } var L = 3 ; document . write ( sum ( L ) ) ;
Product of values of all possible non | Function to find product of all elements in all subsets ; Driver Code
function product ( a , n ) { var ans = 1 ; var val = Math . pow ( 2 , n - 1 ) ; for ( var i = 0 ; i < n ; i ++ ) { ans *= Math . pow ( a [ i ] , val ) ; } return ans ; } var n = 2 ; a = [ 3 , 7 ] document . write ( product ( a , n ) ) ;