codeparrot/xlcost-text-to-code huggingface dataset:
Count of numbers in Array ending with digits of number N | Array to keep the track of digits occurred Initially all are 0 ( false ) ; Function to initialize true if the digit is present ; Variable to store the last digit ; Loop to iterate through every digit of the number N ; Updating the array according to the presence of the digit in n at the array index ; Function to check if the numbers in the array end with the digits of the number N ; Variable to store the count ; Variable to store the last digit ; Checking the presence of the last digit in N ; Function to find the required count ; Driver code ; Preprocessing
let digit = new Uint8Array ( 10 ) ; function digitsPresent ( n ) { let lastDigit ; while ( n != 0 ) { lastDigit = n % 10 ; digit [ lastDigit ] = true ; n = Math . floor ( n / 10 ) ; } } function checkLastDigit ( num ) { let count = 0 ; let lastDigit ; lastDigit = num % 10 ; if ( digit [ lastDigit ] == true ) count ++ ; return count ; } function findCount ( N , K , arr ) { let count = 0 ; for ( let i = 0 ; i < K ; i ++ ) { count = checkLastDigit ( arr [ i ] ) == 1 ? count + 1 : count ; } document . write ( count + " " ) ; } let N = 1731 ; digitsPresent ( N ) ; let K = 5 ; let arr = [ 57 , 6786 , 1111 , 3 , 9812 ] ; findCount ( N , K , arr ) ;
Check if count of even divisors of N is equal to count of odd divisors | Function to check if count of even and odd divisors are equal ; If ( n - 2 ) % 4 is an integer , then return true else return false ; Given Number ; Function Call
function divisorsSame ( n ) { return ( n - 2 ) % 4 == 0 ; } let N = 6 ; if ( divisorsSame ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | Function to find integer ; because 1 st integer is K itself ; Initialize min_d and max_d ; updating min_d and max_d ; break if min digit is 0 ; Driver code
function find ( K , N ) { N -- ; while ( N -- ) { let curr_term = K ; let min_d = 9 ; let max_d = 0 ; while ( curr_term > 0 ) { let r = curr_term % 10 ; min_d = Math . min ( min_d , r ) ; max_d = Math . max ( max_d , r ) ; curr_term = Math . floor ( curr_term / 10 ) ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } let K = 487 ; let N = 2 ; document . write ( find ( K , N ) + " " ) ;
Count of subarrays whose sum is a perfect square | Function to find count of subarrays whose sum is a perfect square . ; To search for index with ( current prefix sum - j * j ) ; Storing the prefix sum ; Used to track the minimum value in prefixSum ; Calculating the prefixSum and tracking the prefixMin ; Below statement is used if array contains negative numbers ; Counts the no of subarrays with perfect square sum ; As 0 is a perfect square , so we initialize 0 th index - key with value 1 ; Here we count the perfect square subarray sum by searching if there is a prefix with sum = ( current prefixSum - ( sq * sq ) ) ; Increasing our subarray count ; Increasing the current prefixSum index value in map by 1 to count the other perfect squares while traversing further ; Driver code ; Prleting the result
function countSubarrays ( arr , n ) { let mp = new Map ( ) ; let prefixSum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let prefixMin = 0 ; prefixSum [ 0 ] = arr [ 0 ] ; prefixMin = Math . min ( prefixMin , prefixSum [ 0 ] ) ; for ( let i = 1 ; i < n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; prefixMin = Math . min ( prefixMin , prefixSum [ i ] ) ; } let countSubs = 0 ; mp . set ( 0 , 1 ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; prefixSum [ i ] - j * j >= prefixMin ; j ++ ) { if ( mp . has ( prefixSum [ i ] - j * j ) ) countSubs += mp . get ( prefixSum [ i ] - j * j ) ; } if ( mp . has ( prefixSum [ i ] ) ) { mp . set ( prefixSum [ i ] , mp . get ( prefixSum [ i ] ) + 1 ) ; } else { mp . set ( prefixSum [ i ] , 1 ) ; } } return countSubs ; } let arr = [ 2 , 3 , - 5 , 6 , - 7 , 4 ] ; let n = arr . length ; let ans = countSubarrays ( arr , n ) ; document . write ( ans ) ;
Find if two given Quadratic equations have common roots or not | function to check if 2 quadratic equations have common roots or not . ; Driver code
function checkSolution ( a1 , b1 , c1 , a2 , b2 , c2 ) { return ( a1 / a2 ) == ( b1 / b2 ) && ( b1 / b2 ) == ( c1 / c2 ) ; } a1 = 1 , b1 = - 5 , c1 = 6 ; a2 = 2 , b2 = - 10 , c2 = 12 ; if ( checkSolution ( a1 , b1 , c1 , a2 , b2 , c2 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not | Function to find the required answer ; Driver code
function checkSolution ( a , b , c ) { if ( b == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } a = 2 , b = 0 , c = 2 ; checkSolution ( a , b , c ) ;
Count of index pairs in array whose range product is a positive integer | Javascript program to find the count of index pairs in the array positive range product ; Condition if number of negative elements is even then increase even_count ; Otherwise increase odd_count ; Condition if current element is negative ; Condition if number of negative elements is even then add even_count in answer ; Otherwise add odd_count in answer ; Driver Code
function positiveProduct ( arr , n ) { let even_count = 0 ; let odd_count = 0 ; let total_count = 0 ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( total_count % 2 == 0 ) { even_count ++ ; } else { odd_count ++ ; } if ( arr [ i ] < 0 ) { total_count ++ ; } if ( total_count % 2 == 0 ) ans += even_count ; else ans += odd_count ; } document . write ( ans ) ; } let A = [ 5 , - 3 , 3 , - 1 , 1 ] ; let size = A . length ; positiveProduct ( A , size ) ;
Pair of integers having difference of their fifth power as X | Function to find a pair of integers A & B such that difference of fifth power is equal to the given number X ; Loop to choose every possible pair with in the range ; Check if equation holds ; Driver Code ; Function Call
function findPair ( x ) { let lim = 120 ; for ( let i = - lim ; i <= lim ; i ++ ) for ( let j = - lim ; j <= lim ; j ++ ) if ( Math . pow ( i , 5 ) - Math . pow ( j , 5 ) == x ) { document . write ( i + " " + j ) ; return ; } document . write ( " " ) ; } let X = 33 ; findPair ( X ) ;
Sum of GCD of all numbers upto N with N itself | Function to Find Sum of GCD of each numbers ; Consider all prime factors of no . and subtract their multiples from result ; Check if p is a prime factor ; If yes , then update no and result ; If no has a prime factor greater than sqrt ( n ) then at - most one such prime factor exists ; Return the result ; Finding GCD of pairs ; Calculate the divisors ; Return count of numbers from 1 to N with GCD d with N ; Check if d1 and d2 are equal then skip this ; Driver code
function getCount ( d , n ) { let no = Math . floor ( n / d ) ; let result = no ; for ( let p = 2 ; p * p <= no ; ++ p ) { if ( no % p == 0 ) { while ( no % p == 0 ) no = Math . floor ( no / p ) ; result = Math . floor ( result - result / p ) ; } } if ( no > 1 ) result = Math . floor ( result - result / no ) ; return result ; } function sumOfGCDofPairs ( n ) { let res = 0 ; for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { let d1 = i ; let d2 = Math . floor ( n / i ) ; res += d1 * getCount ( d1 , n ) ; if ( d1 != d2 ) res += d2 * getCount ( d2 , n ) ; } } return res ; } let n = 12 ; document . write ( sumOfGCDofPairs ( n ) ) ;
Check whether Array represents a Fibonacci Series or not | Returns true if a permutation of arr [ 0. . n - 1 ] can form a Fibonacci Series ; Sort array ; After sorting , check if every element is equal to the sum of previous 2 elements ; Driver code
function checkIsFibonacci ( arr , n ) { if ( n == 1 n == 2 ) return true ; arr . sort ( ( a , b ) => a - b ) ; for ( i = 2 ; i < n ; i ++ ) { if ( ( arr [ i - 1 ] + arr [ i - 2 ] ) != arr [ i ] ) return false ; } return true ; } var arr = [ 8 , 3 , 5 , 13 ] ; var n = arr . length ; if ( checkIsFibonacci ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Last digit in a power of 2 | JavaScript program to find last digit in a power of 2. ; Corner case ; Find the shift in current cycle and return value accordingly ; return 6 ; When n % 4 == 0 ; Driver code
function lastDigit2PowerN ( n ) { if ( n == 0 ) return 1 ; else if ( n % 4 == 1 ) return 2 ; else if ( n % 4 == 2 ) return 4 ; else if ( n % 4 == 3 ) return 8 ; else } for ( var n = 0 ; n < 20 ; n ++ ) document . write ( lastDigit2PowerN ( n ) + " " ) ;
Sum of all subsequences of length K | Function to find nCr ; Function that returns factorial of n ; Function for finding sum of all K length subsequences ; Calculate the sum of array ; Calculate nCk ; Return the final result ; Driver code
function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function sumSubsequences ( arr , n , k ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } var kLengthSubSequence ; kLengthSubSequence = nCr ( n , k ) ; var ans = sum * ( ( k * kLengthSubSequence ) / n ) ; return ans ; } var arr = [ 7 , 8 , 9 , 2 ] ; var K = 2 ; var n = arr . length ; document . write ( sumSubsequences ( arr , n , K ) ) ;
Sum of first K numbers which are not divisible by N | Function to find the sum ; Find the last multiple of N ; Find the K - th non - multiple of N ; Calculate the sum of all elements from 1 to val ; Calculate the sum of all multiples of N between 1 to val ; Driver code
function findSum ( n , k ) { var val = parseInt ( k / ( n - 1 ) ) * n ; var rem = k % ( n - 1 ) ; if ( rem == 0 ) { val = val - 1 ; } else { val = val + rem ; } var sum = parseInt ( ( val * ( val + 1 ) ) / 2 ) ; var x = parseInt ( k / ( n - 1 ) ) ; var sum_of_multiples = parseInt ( ( x * ( x + 1 ) * n ) / 2 ) ; sum -= sum_of_multiples ; return sum ; } var n = 7 , k = 13 ; document . write ( findSum ( n , k ) )
Count of the non | Function to factors of the given number ; Loop to find the divisors of the number 2 ; Loop to find the divisors of the given number upto SQRT ( N ) ; Condition to check if the rest number is also a prime number ; Function to find the non - prime divisors of the given number ; Loop to count the number of the total divisors of given number ; Driver Code ; Function Call
function getFactorization ( x ) { let count = 0 ; let v = [ ] ; while ( x % 2 == 0 ) { count ++ ; x = Math . floor ( x / 2 ) ; } if ( count != 0 ) v . push ( count ) ; for ( let i = 3 ; i <= Math . floor ( Math . sqrt ( x ) ) ; i += 2 ) { count = 0 ; while ( x % i == 0 ) { count ++ ; x = Math . floor ( x / i ) ; } if ( count != 0 ) v . push ( count ) ; } if ( x > 1 ) { v . push ( 1 ) ; } return v ; } function nonPrimeDivisors ( N ) { let v = getFactorization ( N ) ; let ret = 1 ; for ( let i = 0 ; i < v . length ; i ++ ) ret = ret * ( v [ i ] + 1 ) ; ret = ret - v . length ; return ret ; } let N = 8 ; document . write ( nonPrimeDivisors ( N ) ) ;
Check if a number is Full Fibonacci or not | A utility function that returns true if x is perfect square ; Returns true if N is a fibonacci number and false otherwise ; N is fibonacci if one of 5 * N ^ 2 + 4 or 5 * N ^ 2 - 4 or both is a perferct square ; Function to check digits ; Check if all digits are fibonacci or not ; Extract digit ; Check if the current digit is not fibonacci ; Function to check and return if N is a full fibonacci number or not ; Driver code
function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function checkDigits ( n ) { while ( n != 0 ) { var dig = n % 10 ; if ( dig == 4 && dig == 6 && dig == 7 && dig == 9 ) return false ; n /= 10 ; } return true ; } function isFullfibonacci ( n ) { return ( checkDigits ( n ) && isFibonacci ( n ) ) ; } var n = 13 ; if ( isFullfibonacci ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Check whether two numbers are in silver ratio | Function to check that two numbers are in silver ratio ; Swapping the numbers such that A contains the maximum number between these numbers ; First Ratio ; Second Ratio ; Condition to check that two numbers are in silver ratio ; Driver Code ; Function call
function checksilverRatio ( a , b ) { if ( a < b ) { a = a + b ; b = a - b ; a = a - b ; } let ratio1 = ( ( a / b ) * 1000 ) / 1000 ; let ratio2 = Math . floor ( ( ( 2 * a + b ) / a ) * 1000 ) ; ratio2 = ratio2 / 1000 ; if ( ratio1 == ratio2 && ( ratio1 - 2.414 ) == 0 ) { document . write ( " " ) ; return true ; } else { document . write ( " " ) ; return false ; } } let a = 2.414 ; let b = 1 ; checksilverRatio ( a , b ) ;
Nth term where K + 1 th term is product of Kth term with difference of max and min digit of Kth term | Function to find minimum digit in the decimal representation of N ; Loop to find the minimum digit in the number ; Function to find maximum digit in the decimal representation of N ; Loop to find the maximum digit in the number ; Function to find the value of the given function ; Loop to compute the values of the given number ; Driver Code ; Function Call
function MIN ( n ) { let ans = 11 ; while ( n ) { ans = parseInt ( Math . min ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function MAX ( n ) { let ans = - 1 ; while ( n ) { ans = parseInt ( Math . max ( ans , n % 10 ) ) ; n = parseInt ( n / 10 ) ; } return ans ; } function Find_value ( n , k ) { k -- ; let x = 0 ; let y = 0 ; while ( k -- ) { x = parseInt ( MIN ( n ) ) ; y = parseInt ( MAX ( n ) ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } document . write ( n ) ; } let N = 487 , D = 5 ; Find_value ( N , D ) ;
Program to check if N is a Decagonal Number | Function to check if N is a Decagonal Number ; Condition to check if the number is a decagonal number ; Given Number ; Function Call
function isdecagonal ( N ) { let n = ( 3 + Math . sqrt ( 16 * N + 9 ) ) / 8 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 10 ; if ( isdecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Octadecagon number | / Function to check if N is a Octadecagon Number ; Condition to check if the number is a Octadecagon number ; Given Number ; Function Call
function isOctadecagon ( N ) { let n = ( 14 + Math . sqrt ( 128 * N + 196 ) ) / 32 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 18 ; if ( isOctadecagon ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Count of subsequences which consists exactly K prime numbers | Returns factorial of n ; Function to return total number of combinations ; Function check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function for finding number of subsequences which consists exactly K primes ; if number of primes are less thn k ; Driver code
function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function isPrime ( n ) { if ( n <= 1 ) return false ; for ( var i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function countSubsequences ( arr , n , k ) { var countPrime = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( isPrime ( arr [ i ] ) ) countPrime ++ ; } if ( countPrime < k ) return 0 ; return nCr ( countPrime , k ) * Math . pow ( 2 , ( n - countPrime ) ) ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; var K = 3 ; var n = arr . length ; document . write ( countSubsequences ( arr , n , K ) ) ;
Length of the longest alternating even odd subarray | Function to find the longest subarray ; Length of longest alternating subarray ; Iterate in the array ; increment count if consecutive elements has an odd sum ; Store maximum count in longest ; Reinitialize cnt as 1 consecutive elements does not have an odd sum ; Length of ' longest ' can never be 1 since even odd has to occur in pair or more so return 0 if longest = 1 ; Driver code
function longestEvenOddSubarray ( a , n ) { let longest = 1 ; let cnt = 1 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] + a [ i + 1 ] ) % 2 == 1 ) { cnt ++ ; } else { longest = Math . max ( longest , cnt ) ; cnt = 1 ; } } if ( longest == 1 ) return 0 ; return Math . max ( cnt , longest ) ; } let a = [ 1 , 2 , 3 , 4 , 5 , 7 , 8 ] ; let n = a . length ; document . write ( longestEvenOddSubarray ( a , n ) ) ;
Check whether given number N is a Moran Number or not | Function to calculate digit sum ; Function to check if number is prime ; Function to check if number is moran number ; Calculate digit sum ; Check if n is completely divisible by digit sum ; Calculate the quotient ; Check if the number is prime ; Driver code
function digSum ( a ) { let sum = 0 ; while ( a ) { sum += a % 10 ; a = Math . floor ( a / 10 ) ; } return sum ; } function isPrime ( r ) { let s = true ; for ( let i = 2 ; i * i <= r ; i ++ ) { if ( r % i == 0 ) { s = false ; break ; } } return s ; } function moranNo ( n ) { let dup = n ; let sum = digSum ( dup ) ; if ( n % sum == 0 ) { let c = n / sum ; if ( isPrime ( c ) ) { document . write ( " " ) ; return ; } } document . write ( " " + " " ) ; } let n = 21 ; moranNo ( n ) ;
Program to check if N is a Hendecagonal Number | Function to check if N is a Hendecagonal Number ; Condition to check if the number is a hendecagonal number ; Given Number ; Function Call
function ishendecagonal ( N ) { let n = ( 7 + Math . sqrt ( 72 * N + 49 ) ) / 18 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 11 ; if ( ishendecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Hexadecagonal Number | Function to check if N is a hexadecagonal number ; Condition to check if the number is a hexadecagonal number ; Given Number ; Function Call
function ishexadecagonal ( N ) { let n = ( 12 + Math . sqrt ( 112 * N + 144 ) ) / 28 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 16 ; if ( ishexadecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Nonagonal Number | Function to check if N is a is a Nonagonal Number ; Condition to check if the number is a nonagonal number ; Given Number ; Function call
function isnonagonal ( N ) { let n = ( 5 + Math . sqrt ( 56 * N + 25 ) ) / 14 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 9 ; if ( isnonagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Count of decreasing pairs formed from numbers 1 to N | Function to count the possible number of pairs ; if the number is even then the answer in ( N / 2 ) - 1 ; if the number is odd then the answer in N / 2 ; Driver Code
function divParts ( N ) { if ( N % 2 == 0 ) document . write ( ( N / 2 ) - 1 ) ; else document . write ( ( N / 2 ) ) ; } let N = 8 ; divParts ( N ) ;
Count the minimum steps to reach 0 from the given integer N | Function returns min step to reach 0 from N ; Direct possible reduction of value N ; Remaining steps needs to be reduced by 1 ; Summation of both the values ; Return the final answer ; Driver code
function getMinSteps ( n , jump ) { let quotient = Math . floor ( n / jump ) ; let remainder = n % jump ; let steps = quotient + remainder ; return steps ; } let N = 6 , K = 3 ; document . write ( getMinSteps ( N , K ) ) ;
Construct an Array of size N whose sum of cube of all elements is a perfect square | Function to construct an array of size N ; Prints the first N natural numbers ; Driver code
function constructArray ( N ) { for ( let i = 1 ; i <= N ; i ++ ) { document . write ( i + " " ) ; } } let N = 5 ; constructArray ( N ) ;
Program to check if N is a Centered Decagonal Number | Function to check if number N is a Centered decagonal number ; Condition to check if N is Centered Decagonal Number ; Driver Code ; Function call
function isCentereddecagonal ( N ) { let n = ( 5 + Math . sqrt ( 20 * N + 5 ) ) / 10 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 11 ; if ( isCentereddecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Count Sexy Prime Pairs in the given array | A utility function to check if the number n is prime or not ; Base Cases ; Check to skip middle five numbers in below loop ; If n is divisible by i and i + 2 then it is not prime ; A utility function that check if n1 and n2 are SPP ( Sexy Prime Pair ) or not ; Function to find SPP ( Sexy Prime Pair ) pairs from the given array ; Iterate through all pairs ; Increment count if SPP ( Sexy Prime Pair ) pair ; Driver code ; Function call to find SPP ( Sexy Prime Pair ) pair
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( var i = 5 ; i * i <= n ; i += 6 ) { if ( n % i == 0 || n % ( i + 6 ) == 0 ) { return false ; } } return true ; } function SexyPrime ( n1 , n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && Math . abs ( n1 - n2 ) == 6 ) ; } function countSexyPairs ( arr , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( SexyPrime ( arr [ i ] , arr [ j ] ) ) { count ++ ; } } } return count ; } var arr = [ 6 , 7 , 5 , 11 , 13 ] var n = arr . length ; document . write ( countSexyPairs ( arr , n ) ) ;
Find the Largest N digit perfect square number in Base B | Function to find the largest N digit number ; Largest n - digit perfect square ; Print the result ; Driver Code
function nDigitPerfectSquares ( n , b ) { var largest = Math . pow ( Math . ceil ( Math . sqrt ( Math . pow ( b , n ) ) ) - 1 , 2 ) ; document . write ( largest ) ; } var N = 1 , B = 8 ; nDigitPerfectSquares ( N , B ) ;
Find Cube root of a number using Log function | Function to find the cube root ; calculate the cube root ; Return the final answer ; Driver code
function cubeRoot ( n ) { let ans = Math . pow ( 3 , ( 1.0 / 3 ) * ( Math . log ( n ) / Math . log ( 3 ) ) ) ; return ans ; } let N = 8 ; document . write ( cubeRoot ( N ) . toFixed ( 2 ) ) ;
Find the maximum possible value for the given periodic function | Function to return the maximum value of f ( x ) ; Driver Code
function floorMax ( A , B , N ) { let x = Math . min ( B - 1 , N ) ; return Math . floor ( ( A * x ) / B ) ; } let A = 11 , B = 10 , N = 9 ; document . write ( floorMax ( A , B , N ) ) ;
Minimum moves taken to move coin of each cell to any one cell of Matrix | Function to find the minimum number of moves taken to move the element of each cell to any one cell of the square matrix of odd length ; Initializing count to 0 ; Number of layers that are around the centre element ; Iterating over ranger of layers ; Increase the value of count by 8 * k * k ; Driver code
function calculateMoves ( n ) { var count = 0 ; var layers = parseInt ( n / 2 ) ; for ( var k = 1 ; k < layers + 1 ; k ++ ) { count += 8 * k * k ; } return count ; } var N = 5 ; document . write ( calculateMoves ( N ) ) ;
Check if N can be represented as sum of squares of two consecutive integers | Function to check that the a number is sum of squares of 2 consecutive numbers or not ; Condition to check if the a number is sum of squares of 2 consecutive numbers or not ; Driver code ; Function call
function isSumSquare ( N ) { var n = ( 2 + Math . sqrt ( 8 * N - 4 ) ) / 2 ; return ( n - parseInt ( n ) ) == 0 ; } var i = 13 ; if ( isSumSquare ( i ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Centered heptagonal number | Function to check that the number is a Centered heptagonal number ; Condition to check if the number is a Centered heptagonal number ; Driver Code ; Function call
function isCenteredheptagonal ( N ) { let n = ( 7 + Math . sqrt ( 56 * N - 7 ) ) / 14 ; return ( n - parseInt ( n ) ) == 0 ; } let n = 8 ; if ( isCenteredheptagonal ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }