codeparrot/xlcost-text-to-code huggingface dataset:
Check if a number has an odd count of odd divisors and even count of even divisors | Function to check if the number is a perfect square ; Find floating point value of square root of x . ; If square root is an integer ; Function to check if count of even divisors is even and count of odd divisors is odd ; Driver Code
function isPerfectSquare ( x ) { sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function checkFactors ( N ) { if ( isPerfectSquare ( N ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } N = 36 ; checkFactors ( N ) ;
Queries to find the XOR of an Array after replacing all occurrences of X by Y | Stores the bitwise XOR of array elements ; Function to find the total xor ; Loop to find the xor of all the elements ; Function to find the XOR after replacing all occurrences of X by Y for Q queries ; Remove contribution of X from total_xor ; Adding contribution of Y to total_xor ; Print total_xor ; Driver Code
let total_xor ; function initialize_xor ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { total_xor = total_xor ^ arr [ i ] ; } } function find_xor ( X , Y ) { total_xor = total_xor ^ X ; total_xor = total_xor ^ Y ; document . write ( total_xor + " " ) ; } let arr = [ 5 , 7 , 8 , 9 ] ; let n = arr . length ; initialize_xor ( arr , n ) ; let Q = [ [ 5 , 6 ] , [ 8 , 1 ] ] ; for ( let i = 0 ; i < Q . length ; i ++ ) { find_xor ( Q [ i ] [ 0 ] , Q [ i ] [ 1 ] ) ; }
Check whether a given number is an ugly number or not | Function to check if a number is an ugly number or not ; Base Cases ; Condition to check if the number is divided by 2 , 3 , or 5 ; Driver Code
function isUgly ( n ) { if ( n == 1 ) return 1 ; if ( n <= 0 ) return 0 ; if ( n % 2 == 0 ) { return ( isUgly ( n / 2 ) ) ; } if ( n % 3 == 0 ) { return ( isUgly ( n / 3 ) ) ; } if ( n % 5 == 0 ) { return ( isUgly ( n / 5 ) ) ; } return 0 ; } let no = isUgly ( 14 ) ; if ( no == 1 ) document . write ( " " ) ; else document . write ( " " ) ;
Maximum possible GCD for a pair of integers with sum N | Function to find the required GCD value ; If i is a factor of N ; Return the largest factor possible ; If N is a prime number ; Driver code
function maxGCD ( N ) { for ( var i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { return N / i ; } } return 1 ; } var N = 33 ; document . write ( " " + " " + maxGCD ( N ) ) ;
Minimize K whose XOR with given array elements leaves array unchanged | Function to find the minimum value of K in given range ; Declare a set ; Initialize count variable ; Iterate in range [ 1 , 1024 ] ; counter set as 0 ; Iterating through the Set ; Check if the XOR calculated is present in the Set ; If the value of Bitwise XOR inside the given set then increment count ; Check if the value of count is equal to the size of set ; Return minimum value of K ; If no such K is found ; Given array ; Function Call
function min_value ( arr , N ) { let x , X , K ; let S = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { S . push ( arr [ i ] ) ; } let count = 0 ; for ( let i = 1 ; i <= 1024 ; i ++ ) { count = 0 ; for ( let it in S ) { X = ( ( i it ) - ( i & it ) ) ; for ( let j in S ) { if ( S [ j ] == X ) { count ++ ; } } } if ( count == S . length ) { K = i ; return K ; } } return - 1 ; } let arr = [ 1 , 0 , 3 , 3 , 0 , 2 ] ; let N = arr . length ; document . write ( min_value ( arr , N ) ) ;
Junction Numbers | Function to find the sum Of digits of N ; To store sum of N and sumOfdigitsof ( N ) ; extracting digit ; Function to check Junction numbers ; To store count of ways n can be represented as i + SOD ( i ) ; Driver Code ; Function Call
function sum ( n ) { let sum = 0 ; while ( n != 0 ) { let r = n % 10 ; sum = sum + r ; n = parseInt ( n / 10 ) ; } return sum ; } function isJunction ( n ) { let count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { if ( i + sum ( i ) == n ) count ++ ; } return count >= 2 ; } let N = 111 ; if ( isJunction ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Pointer | Function to find the product of digits of a number N ; Function that returns true if n is prime else returns false ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return the smallest prime number greater than N ; Base case ; Loop continuously until isPrime returns true for a number greater than n ; Function to check Pointer - Prime numbers ; Given Number N ; Function Call
function digProduct ( n ) { var product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return product ; } 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 = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function nextPrime ( N ) { if ( N <= 1 ) return 2 ; var prime = N ; var found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } function isPointerPrime ( n ) { if ( isPrime ( n ) && ( n + digProduct ( n ) == nextPrime ( n ) ) ) return true ; else return false ; } var N = 23 ; if ( isPointerPrime ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Perfect Digital Invariants number | Function to calculate x raised to the power y ; Function to check whether the given number is Perfect Digital Invariant number or not ; For each digit in temp ; If satisfies Perfect Digital Invariant condition ; If sum exceeds n , then not possible ; Given Number N ; Function Call
function power ( x , y ) { if ( y == 0 ) { return 1 ; } if ( y % 2 == 0 ) { return ( power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ) ; } return ( x * power ( x , Math . floor ( y / 2 ) ) * power ( x , Math . floor ( y / 2 ) ) ) ; } function isPerfectDigitalInvariant ( x ) { for ( var fixed_power = 1 ; ; fixed_power ++ ) { var temp = x , sum = 0 ; while ( temp ) { var r = temp % 10 ; sum += power ( r , fixed_power ) ; temp = Math . floor ( temp / 10 ) ; } if ( sum == x ) { return true ; } if ( sum > x ) { return false ; } } } var N = 4150 ; if ( isPerfectDigitalInvariant ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Brilliant Numbers | Function to generate all prime numbers less than n ; Initialize all entries of let array as true . A value in isPrime [ i ] will finally be false if i is Not a prime ; If isPrime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to return the number of digits in a number ; Function to check if N is a Brilliant number ; Generating primes using Sieve ; Traversing all numbers to find first pair ; Given Number ; Function Call
function SieveOfEratosthenes ( n , isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) isPrime [ i ] = false ; } } } function countDigit ( n ) { let count = 0 ; while ( n != 0 ) { n = parseInt ( n / 10 ) ; ++ count ; } return count ; } function isBrilliant ( n ) { let flag = 0 ; let isPrime = Array ( n + 1 ) . fill ( true ) ; SieveOfEratosthenes ( n , isPrime ) ; for ( let i = 2 ; i < n ; i ++ ) { let x = n / i ; if ( isPrime [ i ] && isPrime [ x ] && ( x * i ) == n ) { if ( countDigit ( i ) == countDigit ( x ) ) return true ; } } return false ; } let n = 1711 ; if ( isBrilliant ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Icosikaienneagonal Number | Function to Find the Nth icosikaienneagonal Number ; Driver Code
function icosikaienneagonalNum ( n ) { return ( 27 * n * n - 25 * n ) / 2 ; } let n = 3 ; document . write ( icosikaienneagonalNum ( n ) ) ;
Sum of minimum value of x and y satisfying the equation ax + by = c | Javascript program for the above approach ; x and y store solution of equation ax + by = g ; Euclidean Algorithm ; store_gcd returns the gcd of a and b ; Function to find any possible solution ; Condition if solution does not exists ; Adjusting the sign of x0 and y0 ; Function to shift solution ; Shifting to obtain another solution ; Function to find minimum value of x and y ; g is the gcd of a and b ; Store sign of a and b ; If x is less than 0 , then shift solution ; If y is less than 0 , then shift solution ; Find intersection such that both x and y are positive ; miny is value of y corresponding to minx ; Returns minimum value of x + y ; Given a , b , and c ; Function call
let x = 0 , y = 0 , x1 = 0 , y1 = 0 ; let x0 = 0 , y0 = 0 , g = 0 ; function gcd ( a , b ) { if ( b == 0 ) { x = 1 ; y = 0 ; return a ; } let store_gcd = gcd ( b , a % b ) ; x = y1 ; y = x1 - y1 * parseInt ( a / b , 10 ) ; return store_gcd ; } function possible_solution ( a , b , c ) { g = gcd ( Math . abs ( a ) , Math . abs ( b ) ) ; if ( c % g != 0 ) { return 0 ; } x0 *= parseInt ( c / g , 10 ) ; y0 *= parseInt ( c / g , 10 ) ; if ( a < 0 ) x0 *= - 1 ; if ( b < 0 ) y0 *= - 1 ; return 1 ; } function shift_solution ( a , b , shift_var ) { x += shift_var * b ; y -= shift_var * a ; } function find_min_sum ( a , b , c ) { let x = 0 , y = 0 , g = 0 ; if ( possible_solution ( a , b , c ) == 0 ) return - 1 ; if ( g != 0 ) { a = parseInt ( a / g , 10 ) ; b = parseInt ( b / g , 10 ) ; } let sign_a = a > 0 ? + 1 : - 1 ; let sign_b = b > 0 ? + 1 : - 1 ; shift_solution ( a , b , parseInt ( - x / b , 10 ) ) ; if ( x < 0 ) shift_solution ( a , b , sign_b ) ; let minx1 = x ; shift_solution ( a , b , parseInt ( y / a , 10 ) ) ; if ( y < 0 ) shift_solution ( a , b , - sign_a ) ; let minx2 = x ; if ( minx2 > x ) { let temp = minx2 ; minx2 = x ; x = temp ; } let minx = Math . max ( minx1 , minx2 ) ; if ( minx > x ) return - 1 ; let miny = parseInt ( ( c - a * x ) / b , 10 ) ; return ( miny + minx ) ; } let a = 2 , b = 2 , c = 0 ; document . write ( find_min_sum ( a , b , c ) ) ;
Second hexagonal numbers | Function to find N - th term in the series ; Driver code
function findNthTerm ( n ) { document . write ( n * ( 2 * n + 1 ) ) ; } N = 4 ; findNthTerm ( N ) ;
Apocalyptic Number | Function to check if N isApocalyptic ; Given Number N ; Function Call
function isApocalyptic ( n ) { var x = Math . pow ( 2 , n ) ; if ( x . toString ( ) . indexOf ( ' ' ) ) return true return false } var N = 157 ; if ( isApocalyptic ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Duffinian Numbers | Recursive function to return gcd of a and b ; Function to calculate the sum of all divisors of a given number ; Sum of divisors ; Find all divisors of num ; if ' i ' is divisor of ' n ' ; If both divisors are same then add it once ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Function to check if n is an Duffinian number ; Calculate the sum of divisors ; If number is prime return false ; Find the gcd of n and sum of divisors of n ; Returns true if N and sumDivisors are relatively prime ; Given Number ; Function Call
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function divSum ( n ) { let result = 0 ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + n + 1 ) ; } function isDuffinian ( n ) { let sumDivisors = divSum ( n ) ; if ( sumDivisors == n + 1 ) return false ; let hcf = gcd ( n , sumDivisors ) ; return hcf == 1 ; } let n = 36 ; if ( isDuffinian ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Kummer Numbers | JavaScript program to find Kummer number upto n terms ; vector to store all prime less than and equal to 10 ^ 6 ; Function for the Sieve of Sundaram . This function stores all prime numbers less than MAX in primes ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than MAX , we reduce MAX to half This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j ; Main logic of Sundaram . Mark all numbers which do not generate prime number by doing 2 * i + 1 ; Since 2 is a prime number ; Prlet other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Function to calculate nth Kummer number ; Multiply first n primes ; return nth Kummer number ; Driver Code
let MAX = 1000000 ; let primes = [ ] ; function sieveSundaram ( ) { let marked = Array . from ( { length : MAX / 2 + 1 } , ( _ , i ) => 0 ) ; for ( let i = 1 ; i <= ( Math . sqrt ( MAX ) - 1 ) / 2 ; i ++ ) for ( let j = ( i * ( i + 1 ) ) << 1 ; j <= MAX / 2 ; j += 2 * i + 1 ) marked [ j ] = true ; primes . push ( 2 ) ; for ( let i = 1 ; i <= MAX / 2 ; i ++ ) if ( marked [ i ] == false ) primes . push ( 2 * i + 1 ) ; } function calculateKummer ( n ) { let result = 1 ; for ( let i = 0 ; i < n ; i ++ ) result = result * primes [ i ] ; return - 1 + result ; } let n = 5 ; sieveSundaram ( ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( calculateKummer ( i ) + " " ) ;
Check if given number contains a digit which is the average of all other digits | Function which checks if a digits exists in n which is the average of all other digits ; Calculate sum of digits in n ; Store the digits ; Increase the count of digits in n ; If average of all digits is an integer ; Otherwise ; Driver Code
function check ( n ) { var digits = new Set ( ) ; var temp = n ; var sum = 0 ; var count = 0 ; while ( temp > 0 ) { sum += temp % 10 ; digits . add ( temp % 10 ) ; count ++ ; temp = parseInt ( temp / 10 ) ; } if ( sum % count == 0 && digits . has ( sum / count ) ) document . write ( " " ) ; else document . write ( " " ) ; } var n = 42644 ; check ( n ) ;
Count of lexicographically smaller characters on right | function to count the smaller characters at the right of index i ; store the length of string ; for each index initialize count as zero ; increment the count if characters are smaller than at ith index ; print the count of characters smaller than the index i ; input string
function countSmaller ( str ) { var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { var cnt = 0 ; for ( var j = i + 1 ; j < n ; j ++ ) { if ( str [ j ] < str [ i ] ) { cnt += 1 ; } } document . write ( cnt + " " ) ; } } var str = " " ; countSmaller ( str ) ;
Find the smallest contiguous sum pair in an Array | Function to find the smallest sum contiguous pair ; Stores the contiguous pair ; Initialize minimum sum ; Checking for minimum value ; Add to pair ; Updating pair ; Driver Code
function smallestSumpair ( arr , n ) { let pair = [ ] ; let min_sum = Number . MAX_VALUE , i ; for ( i = 1 ; i < n ; i ++ ) { if ( min_sum > ( arr [ i ] + arr [ i - 1 ] ) ) { min_sum = arr [ i ] + arr [ i - 1 ] ; if ( pair . length == 0 ) { pair . push ( arr [ i - 1 ] ) ; pair . push ( arr [ i ] ) ; } else { pair [ 0 ] = arr [ i - 1 ] ; pair [ 1 ] = arr [ i ] ; } } } return pair ; } let arr = [ 4 , 9 , - 3 , 2 , 0 ] ; let N = arr . length ; let pair = smallestSumpair ( arr , N ) ; document . write ( pair [ 0 ] + " " + pair [ 1 ] ) ;
Add two integers of different base and represent sum in smaller base of the two | Javascript Program to find the sum of two integers of different bases . ; Initialize power of base ; Initialize result ; Decimal equivalent is str [ len - 1 ] * 1 + str [ len - 2 ] * base + str [ len - 3 ] * ( base ^ 2 ) + ... ; Maximum base - 36 String base_num = " " ; ; print ans in reverse order ; Driver Code ; Integer in base 10 ; Sum of integers ; Minimum Base ; Sum of integers in Min Base
function val ( c ) { if ( c >= ' ' && c <= ' ' ) return c . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; else return c . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 10 ; } function convert ( num , bases ) { let len = ( num . length ) ; let power = 1 ; let res = 0 ; let i ; for ( i = len - 1 ; i >= 0 ; i -- ) { res += val ( num [ i ] ) * power ; power = power * bases ; } return res ; } function dec_to_base ( num , bases ) { let base_num = [ ] ; while ( num > 0 ) { let dig = ( num % bases ) ; if ( dig < 10 ) base_num . push ( ( dig ) . toString ( ) ) ; else base_num . append ( ( ' ' . charCodeAt ( 0 ) + dig - 10 ) . toString ( ) ) ; num = Math . floor ( num / bases ) ; } for ( let i = base_num . length - 1 ; i >= 0 ; i -- ) document . write ( base_num [ i ] ) ; } let a = " " ; let b = " " ; let base_a = 6 ; let base_b = 8 ; let a10 = convert ( a , base_a ) ; let b10 = convert ( b , base_b ) ; let summ = a10 + b10 ; let min_base = Math . min ( base_a , base_b ) ; dec_to_base ( summ , min_base ) ;
Sum of the products of same placed digits of two numbers | Function to find the sum of the products of their corresponding digits ; Loop until one of the numbers have no digits remaining ; Driver Code
function sumOfProductOfDigits ( n1 , n2 ) { let sum = 0 ; while ( n1 > 0 && n2 > 0 ) { sum += ( ( n1 % 10 ) * ( n2 % 10 ) ) ; n1 = Math . floor ( n1 / 10 ) ; n2 = Math . floor ( n2 / 10 ) ; } return sum ; } let n1 = 25 ; let n2 = 1548 ; document . write ( sumOfProductOfDigits ( n1 , n2 ) ) ;
Print all permutations of a number N greater than itself | Function to print all the permutation which are greater than N itself ; Iterate and count the number of digits in N ; vector to print the permutations of N ; Store digits of N in the vector num ; Iterate over every permutation of N which is greater than N ; Print the current permutation of N ; Function to print all the permutation which are greater than N itself ; Driver code
function printPermutation ( N ) { let temp = N , count = 0 ; while ( temp > 0 ) { count ++ ; temp = parseInt ( temp / 10 , 10 ) ; } let num = new Array ( count ) ; num . fill ( 0 ) ; while ( N > 0 ) { num [ count -- - 1 ] = N % 10 ; N = parseInt ( N / 10 , 10 ) ; } while ( next_permutation ( num ) ) { for ( let i = 0 ; i < num . length ; i ++ ) document . write ( num [ i ] ) ; document . write ( " " ) ; } } function next_permutation ( p ) { for ( let a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( let b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { let t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } let N = 324 ; printPermutation ( N ) ;
Count of ways to represent N as sum of a prime number and twice of a square | JavaScript implementation to count the number of ways a number can be written as sum of prime number and twice a square ; Function to mark all the prime numbers using sieve ; Loop to mark the prime numbers upto the Square root of N ; Loop to store the prime numbers in an array ; Function to find the number ways to represent a number as the sum of prime number and square of a number ; Loop to iterate over all the possible prime numbers ; Increment the count if the given number is a valid number ; Driver Code ; Function Call
let n = 500000 - 2 ; let v = [ ] ; function sieveoferanthones ( ) { let prime = Array . from ( { length : n + 1 } , ( _ , i ) => true ) ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( prime [ i ] ) for ( let j = i * i ; j <= n ; j += i ) { prime [ j ] = false ; } } for ( let i = 2 ; i < n ; i ++ ) { if ( prime [ i ] ) v . push ( i ) ; } } function numberOfWays ( n ) { let count = 0 ; for ( let j = 1 ; 2 * ( Math . pow ( j , 2 ) ) < n ; j ++ ) { for ( let i = 1 ; v [ i ] + 2 <= n ; i ++ ) { if ( n == v [ i ] + ( 2 * ( Math . pow ( j , 2 ) ) ) ) count ++ ; } } document . write ( count + " " ) ; } sieveoferanthones ( ) ; let N = 9 ; numberOfWays ( N ) ;
Program to convert Degree to Radian | Function for conversion ; Driver code
function Convert ( degree ) { let pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } let degree = 30 ; let radian = Convert ( degree ) ; document . write ( radian ) ;
Program to convert a Binary Number to Hexa | Function to convert Binary to HexaDecimal ; Iterating through the bits backwards ; Computing the HexaDecimal Number formed so far and storing it in a vector . ; Reinitializing all variables for next group . ; Printing the Hexadecimal number formed so far . ; Driver Code ; Function Call
function bToHexaDecimal ( s ) { let len = s . length , check = 0 ; let num = 0 , sum = 0 , mul = 1 ; let ans = new Array ( ) ; for ( let i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum <= 9 ) ans . push ( String . fromCharCode ( sum + ' ' . charCodeAt ( 0 ) ) ) ; else ans . push ( String . fromCharCode ( sum + 55 ) ) ; check = 0 ; sum = 0 ; mul = 1 ; } } len = ans . length ; for ( let i = len - 1 ; i >= 0 ; i -- ) document . write ( ans [ i ] ) ; } let s = " " ; bToHexaDecimal ( s ) ;
Find the sum of the first N Dodecagonal Numbers | Function to find the N - th dodecagonal number ; Formula to calculate N - th dodecagonal number ; Function to find the sum of the first N dodecagonal numbers ; Variable to get the sum ; Iterating through the first N numbers ; Compute the sum ; Driver Code ; Display first Nth centered_decagonal number
function Dodecagonal_num ( n ) { return ( 5 * n * n - 4 * n ) ; } function sum_Dodecagonal_num ( n ) { let summ = 0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { summ += Dodecagonal_num ( i ) ; } return summ ; } let n = 5 ; document . write ( sum_Dodecagonal_num ( n ) ) ;
Program to check if N is a Myriagon Number | Function to check if N is a Myriagon Number ; Condition to check if the number is a Myriagon number ; Given Number ; Function call
function isMyriagon ( N ) { n = ( 9996 + Math . sqrt ( 79984 * N + 99920016 ) ) / 19996 ; return ( n - parseInt ( n ) ) == 0 ; } N = 10000 ; if ( isMyriagon ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Heptagonal Number | Function to check if N is a Heptagonal number ; Condition to check if the number is a heptagonal number ; Given Number ; Function call
function isheptagonal ( N ) { var n = ( 3 + Math . sqrt ( 40 * N + 9 ) ) / 10 ; return ( n - parseInt ( n ) ) == 0 ; } var N = 7 ; if ( isheptagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Enneadecagonal Number | Function to check if number N is a enneadecagonal number ; Condition to check if N is a enneadecagonal number ; Given number ; Function call
function isenneadecagonal ( N ) { let n = parseFloat ( 15 + Math . sqrt ( 136 * N + 225 ) ) / 34 ; return ( n - parseInt ( n ) ) == 0 } let N = 19 ; if ( isenneadecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to check if N is a Centered Tridecagonal Number | Function to check if the number N is a Centered tridecagonal number ; Condition to check if the N is a Centered tridecagonal number ; Given Number ; Function call
function isCenteredtridecagonal ( N ) { let n = ( 13 + Math . sqrt ( 104 * N + 65 ) ) / 26 ; return ( n - parseInt ( n ) ) == 0 ; } let N = 14 ; if ( isCenteredtridecagonal ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Orbit counting theorem or Burnside 's Lemma | Utility function ; Function to find result using Orbit counting theorem or Burnside 's Lemma ; According to Burnside 's Lemma  calculate distinct ways for each  rotation ; Find GCD ; Divide By N ; Prlet the distinct ways ; N stones and M colors ; Function call
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function countDistinctWays ( N , M ) { let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let K = gcd ( i , N ) ; ans += Math . pow ( M , K ) ; } ans /= N ; document . write ( ans ) ; } let N = 4 , M = 3 ; countDistinctWays ( N , M ) ;
Find the Nth natural number which is not divisible by A | Javascript code to Find the Nth number which is not divisible by A from the series ; Find the quotient and the remainder when k is divided by n - 1 ; If the remainder is not 0 multiply n by q and subtract 1 if remainder is 0 then multiply n by q and add the remainder ; Print the answer ; Driver code
function findNum ( n , k ) { let q = parseInt ( k / ( n - 1 ) ) ; let r = k % ( n - 1 ) ; let a ; if ( r != 0 ) a = ( n * q ) + r ; else a = ( n * q ) - 1 ; document . write ( a ) ; } let A = 4 , N = 6 ; findNum ( A , N ) ;