codeparrot/xlcost-text-to-code huggingface dataset:
Count of ways to split N into Triplets forming a Triangle | Function to return the required number of ways ; Check if a , b and c can form a triangle ; Return number of ways ; Driver Code
function Numberofways ( n ) { var count = 0 ; for ( var a = 1 ; a < n ; a ++ ) { for ( var b = 1 ; b < n ; b ++ ) { var c = n - ( a + b ) ; if ( a + b > c && a + c > b && b + c > a ) { count ++ ; } } } return count ; } var n = 15 ; document . write ( Numberofways ( n ) ) ;
Count of pairs having each element equal to index of the other from an Array | Function to print the count of pair ; Iterate over all the elements of the array ; Increment the count ; Print the result ; Driver Code
function countPairs ( N , arr ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( i == arr [ arr [ i ] - 1 ] - 1 ) { count ++ ; } } document . write ( count / 2 ) ; } let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ; let arr = [ 2 , 1 , 4 , 3 ] ; let N = arr . length ; countPairs ( N , arr ) ;
Find length of longest Fibonacci like subsequence | Function to return the max Length of Fibonacci subsequence ; Store all array elements in a hash table ; check until next fib element is found ; next element of fib subseq ; Driver program
function LongestFibSubseq ( A , n ) { var S = new Set ( A ) ; var maxLen = 0 , x , y ; for ( var i = 0 ; i < n ; ++ i ) { for ( var j = i + 1 ; j < n ; ++ j ) { x = A [ j ] ; y = A [ i ] + A [ j ] ; var length = 2 ; while ( S . has ( y ) ) { var z = x + y ; x = y ; y = z ; maxLen = Math . max ( maxLen , ++ length ) ; } } } return maxLen >= 3 ? maxLen : 0 ; } var A = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ; var n = A . length ; document . write ( LongestFibSubseq ( A , n ) ) ;
Maximize count of elements that can be selected having minimum difference between their sum and K | Function to count maximum number of elements that can be selected ; Sorting the array ; Traverse the array ; Add the current element to the sum ; If sum exceeds k ; Increment count ; Returning the count ; Driver Code ; Function call
function CountMaximum ( arr , n , k ) { arr . sort ( ) ; let sum = 0 , count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum > k ) break ; count ++ ; } return count ; } let arr = [ 30 , 30 , 10 , 10 ] ; let n = 4 ; let k = 50 ; document . write ( CountMaximum ( arr , n , k ) ) ;
Maximum types of candies a person can eat if only N / 2 of them can be eaten | Function to find number of candy types ; Declare a hashset to store candies ; Traverse the given array and inserts element into set ; Return the result ; Function to find maximum number of types of candies a person can eat ; Store the number of candies allowed to eat ; Store the number of candy types ; Return the result ; Given Input ; Function Call
function num_candyTypes ( candies ) { let s = new Set ( ) ; for ( let i = 0 ; i < candies . length ; i ++ ) { s . add ( candies [ i ] ) ; } return s . size ; } function distribute_candies ( candies ) { let allowed = candies . length / 2 ; let types = num_candyTypes ( candies ) ; if ( types < allowed ) document . write ( types ) ; else document . write ( allowed ) ; } let candies = [ 4 , 4 , 5 , 5 , 3 , 3 ] ; distribute_candies ( candies ) ;
Length of diagonals of a Rhombus using length of Side and vertex Angle | Function to calculate the length of diagonals of a rhombus using length of sides and vertex angle ; Driver Code
function Length_Diagonals ( a , theta ) { let p = a * Math . sqrt ( 2 + ( 2 * Math . cos ( theta * ( Math . PI / 180 ) ) ) ) ; let q = a * Math . sqrt ( 2 - ( 2 * Math . cos ( theta * ( Math . PI / 180 ) ) ) ) ; return [ p , q ] ; } let A = 6 ; let theta = 45 ; let ans = Length_Diagonals ( A , theta ) ; document . write ( ans [ 0 ] . toFixed ( 2 ) + " " + ans [ 1 ] . toFixed ( 2 ) ) ;
Count of even and odd set bit with array element after XOR with K | Function to get no of set bits in binary representation of positive integer n ; Function to store EVEN and odd variable ; Store the count of even and odd set bit ; Count the set bit using in built function ; Count of set - bit of K ; If y is odd then , count of even and odd set bit will be interchanged ; Else it will remain same as the original array ; Driver 's Code ; Function call to count even and odd
function __builtin_popcount ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function countEvenOdd ( arr , n , K ) { let even = 0 , odd = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let x = __builtin_popcount ( arr [ i ] ) ; if ( x % 2 == 0 ) even ++ ; else odd ++ ; } let y ; y = __builtin_popcount ( K ) ; if ( ( y & 1 ) != 0 ) { document . write ( " " + odd + " " + even ) ; } else { document . write ( " " + even + " " + odd ) ; } } let arr = [ 4 , 2 , 15 , 9 , 8 , 8 ] ; let K = 3 ; let n = arr . length ; countEvenOdd ( arr , n , K ) ;
Number of ways to choose a pair containing an even and an odd number from 1 to N | Driver code
let N = 6 ; let Even = Math . floor ( N / 2 ) ; let Odd = N - Even ; document . write ( Even * Odd ) ;
Count triples with Bitwise AND equal to Zero | Function to find the number of triplets whose Bitwise AND is 0. ; Stores the count of triplets having bitwise AND equal to 0 ; Stores frequencies of all possible A [ i ] & A [ j ] ; Traverse the array ; Update frequency of Bitwise AND of all array elements with a ; Traverse the array ; Update frequency of Bitwise AND of all array elements with a ; If bitwise AND of triplet is zero , increment cnt ; Return the number of triplets whose Bitwise AND is 0. ; Input Array ; Function Call
function countTriplets ( A ) { var cnt = 0 ; var tuples = new Map ( ) ; A . forEach ( a => { A . forEach ( b => { if ( tuples . has ( a & b ) ) tuples . set ( a & b , tuples . get ( a & b ) + 1 ) else tuples . set ( a & b , 1 ) } ) ; } ) ; A . forEach ( a => { tuples . forEach ( ( value , key ) => { if ( ( key & a ) == 0 ) cnt += value ; } ) ; } ) ; return cnt ; } var A = [ 2 , 1 , 3 ] ; document . write ( countTriplets ( A ) ) ;
Count ways to reach a score using 1 and 2 with no consecutive 2 s | Bottom up approach for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; noOfWays [ i ] will store count for value i . 3 extra values are to take care of cornser case n = 0 ; Loop till " n + 1" to compute value for " n " ; number of ways if first run is 1 number of ways if first run is 2 and second run is 1 ; Driver code
function CountWays ( n ) { var noOfWays = Array ( n + 3 ) . fill ( 0 ) ; noOfWays [ 0 ] = 1 ; noOfWays [ 1 ] = 1 ; noOfWays [ 2 ] = 1 + 1 ; for ( var i = 3 ; i < n + 1 ; i ++ ) { noOfWays [ i ] = noOfWays [ i - 1 ] + noOfWays [ i - 3 ] ; } return noOfWays [ n ] ; } var n = 5 ; document . write ( CountWays ( n ) ) ;
Program to print Spiral Pattern |  ; Create row and col to traverse rows and columns ; Variable to determine the movement r = right , l = left , d = down , u = upper ; Array for matrix ; Assign the value ; switch - case to determine the next index ; If right , go right ; If left , go left ; If up , go up ; If down , go down ; Check if the matrix has reached array boundary ; Add the left size for the next boundary ; If 2 rotations has been made , decrease the size left by 1 ; switch - case to rotate the movement ; If right , rotate to down ; If down , rotate to left ; If left , rotate to up ; If up , rotate to right ; Print the matrix ; Get the size of size ; Print the Spiral Pattern
function printSpiral ( size ) { let row = 0 , col = 0 ; let boundary = size - 1 ; let sizeLeft = size - 1 ; let flag = 1 ; let move = ' ' ; let matrix = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) { matrix [ i ] = new Array ( size ) . fill ( 0 ) ; } for ( let i = 1 ; i < size * size + 1 ; i ++ ) { matrix [ row ] [ col ] = i ; switch ( move ) { case ' ' : col += 1 ; break ; case ' ' : col -= 1 ; break ; case ' ' : row -= 1 ; break ; case ' ' : row += 1 ; break ; } if ( i == boundary ) { boundary += sizeLeft ; if ( flag != 2 ) { flag = 2 ; } else { flag = 1 ; sizeLeft -= 1 ; } switch ( move ) { case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; case ' ' : move = ' ' ; break ; } } } for ( row = 0 ; row < size ; row ++ ) { for ( col = 0 ; col < size ; col ++ ) { let n = matrix [ row ] [ col ] ; if ( n < 10 ) document . write ( n + " " ) ; else document . write ( n + " " ) ; } document . write ( " " ) ; } } let size = 5 ; printSpiral ( size ) ;
Find the last player to be able to flip a character in a Binary String | Function to check if player A wins the game or not ; Stores size of the groups of 0 s ; Stores size of the group of 0 s ; Traverse the array ; Increment c by 1 if a [ i ] is 0 ; Otherwise , push the size in array and reset c to 0 ; If there is no substring of odd length consisting only of 0 s ; If there is only 1 substring of odd length consisting only of 0 s ; Otherwise ; Stores the size of the largest and second largest substrings of 0 s ; Traverse the array v [ ] ; If current element is greater than first , then update both first and second ; If arr [ i ] is in between first and second , then update second ; If the condition is satisfied ; Driver code
function findWinner ( a , n ) { let v = [ ] ; let c = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == ' ' ) { c ++ ; } else { if ( c != 0 ) v . push ( c ) ; c = 0 ; } } if ( c != 0 ) v . push ( c ) ; if ( v . length == 0 ) { document . write ( " " ) ; return ; } if ( v . length == 1 ) { if ( ( v [ 0 ] & 1 ) != 0 ) document . write ( " " ) ; else document . write ( " " ) ; return ; } let first = Number . MIN_VALUE ; let second = Number . MIN_VALUE ; for ( let i = 0 ; i < v . length ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } if ( ( first & 1 ) != 0 && parseInt ( ( first + 1 ) / 2 , 10 ) > second ) document . write ( " " ) ; else document . write ( " " ) ; } let S = " " ; let N = S . length ; findWinner ( S , N ) ;
Check if K palindromic strings can be formed from a given string | function to check whether the string is K palindrome or not ; map to frequency of character ; Check when k is given as same as length of string ; storing the frequency of every character in map ; if K is greater than size of string then return false ; check that number of character having the odd frequency ; if k is less than number of odd frequency character then it is again false other wise true ; Driver code
function can_Construct ( S , K ) { var m = new Map ( ) ; var i = 0 , j = 0 , p = 0 ; if ( S . length == K ) { return true ; } for ( i = 0 ; i < S . length ; i ++ ) { if ( m . has ( S [ i ] ) ) m . set ( S [ i ] , m . get ( S [ i ] ) + 1 ) else m . set ( S [ i ] , 1 ) } if ( K > S . length ) { return false ; } else { m . forEach ( ( value , key ) => { if ( value % 2 != 0 ) { p = p + 1 ; } } ) ; } if ( K < p ) { return false ; } return true ; } var S = " " ; var K = 4 ; if ( can_Construct ( S , K ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Check if two strings are same ignoring their cases | Function to compare two strings ignoring their cases ; Convert to lowercase using toLowerCase function ; Comparing both using inbuilt function ; if strings are equal , return true otherwise false ; Function to print the same or not same if strings are equal or not equal ; Driver Code
function equalIgnoreCase ( str1 , str2 ) { let i = 0 ; str1 = str1 . toLowerCase ( ) ; str2 = str2 . toLowerCase ( ) ; let x = ( str1 == ( str2 ) ) ; return x == true ; } function equalIgnoreCaseUtil ( str1 , str2 ) { let res = equalIgnoreCase ( str1 , str2 ) ; if ( res == true ) document . write ( " " ) ; else document . write ( " " ) ; } let str1 , str2 ; str1 = " " ; str2 = " " ; equalIgnoreCaseUtil ( str1 , str2 ) ; str1 = " " ; str2 = " " ; equalIgnoreCaseUtil ( str1 , str2 ) ;
Program to print Step Pattern | function to print the steps ; declare a flag ; traverse through all the characters in the string ; if the x value is 0. . then we must increment till n ... set flag to true ; if the x value is n - 1 then we must decrement till 0 ... set flag as false ; print x * s ; checking whether to increment or decrement x ; Get the String and the number n ; calling the function
function steps ( str , n ) { var flag ; var x = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( x == 0 ) flag = true ; if ( x == n - 1 ) flag = false ; for ( var j = 0 ; j < x ; j ++ ) document . write ( " " ) ; document . write ( str [ i ] + " " ) ; if ( flag == true ) x ++ ; else x -- ; } } var n = 4 ; var str = " " ; document . write ( " " + str + " " ) ; document . write ( " " + n + " " ) ; steps ( str , n ) ;
Frequency Measuring Techniques for Competitive Programming | Javascript program to count frequencies of array items ; Mark all array elements as not visited ; Traverse through array elements and count frequencies ; Skip this element if already processed ; Count frequency ; Driver Code
function countFreq ( arr , n ) { let visited = new Array ( n ) ; visited . fill ( false ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == true ) continue ; let count = 1 ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { visited [ j ] = true ; count ++ ; } } document . write ( arr [ i ] + " " + count + " " ) ; } } let arr = [ 10 , 20 , 20 , 10 , 10 , 20 , 5 , 20 ] ; let n = arr . length ; countFreq ( arr , n ) ;
Check divisibility of binary string by 2 ^ k | Function to check whether given binary number is evenly divisible by 2 ^ k or not ; Count of number of 0 from last ; If count = k , number is evenly divisible , so returns true else false ; First example ; Second example
function isDivisible ( str , k ) { let n = str . length ; let c = 0 ; for ( let i = 0 ; i < k ; i ++ ) if ( str [ n - i - 1 ] == ' ' ) c ++ ; return ( c == k ) ; } let str1 = " " ; let k = 2 ; if ( isDivisible ( str1 , k ) == true ) document . write ( " " + " " ) ; else document . write ( " " ) ; let str2 = " " ; k = 2 ; if ( isDivisible ( str2 , k ) == true ) document . write ( " " ) ; else document . write ( " " ) ;
Check if any anagram of a string is palindrome or not | Javascript program to Check if any anagram of a string is palindrome or not ; function to check whether characters of a string can form a palindrome ; Create a count array and initialize all values as 0 ; For each character in input strings , increment count in the corresponding count array ; Count odd occurring characters ; Return true if odd count is 0 or 1 , ; Driver program to test to print printDups
let NO_OF_CHARS = 256 ; function canFormPalindrome ( str ) { let count = new Array ( NO_OF_CHARS ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] . charCodeAt ( ) ] ++ ; let odd = 0 ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( ( count [ i ] & 1 ) != 0 ) odd ++ ; if ( odd > 1 ) return false ; } return true ; } document . write ( canFormPalindrome ( " " ) ? " " + " " : " " + " " ) ; document . write ( canFormPalindrome ( " " ) ? " " : " " ) ;
Program to check if input is an integer or a string | Returns true if s is a number else false ; Saving the input in a string ; Function returns 1 if all elements are in range '0 ▁ - ▁ 9' ; Function returns 0 if the input is not an integer
function isNumber ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) if ( s [ i ] < ' ' s [ i ] > ' ' ) return false ; return true ; } let str = " " ; if ( isNumber ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;
Print reverse of a string using recursion | Function to print reverse of the passed string ; Driver program to test above function
function reverse ( str , len ) { if ( len == str . length ) { return ; } reverse ( str , len + 1 ) ; document . write ( str [ len ] ) ; } let a = " " ; reverse ( a , 0 ) ;
Probability of distributing given balls into two halves having equal count of distinct colors | Stores the count of distinct colors in box1 ; Stores the count of distinct colors in box2 ; Function to calculate the required probability ; Calculate factorial from [ 1 , 10 ] ; Assign all distinct balls to second box ; Total number of balls ; Calculate total number of balls ; If K is an odd number ; Total ways of distributing the balls in two equal halves ; Required number of ways ; Return the required probability ; Function to calculate total number of possible distributions which satisfies the given conditions ; If used balls is equal to K / 2 ; If box1 is equal to box2 ; Base condition ; Stores the number of ways of distributing remaining balls without including the current balls in box1 ; Increment box1 by one ; Iterate over the range [ 1 , balls [ i ] ] ; If all the balls goes to box1 , then decrease box2 by one ; Total number of ways of selecting j balls ; Increment res by total number of valid ways of distributing the remaining balls ; Decrement box1 by one ; Increment box2 by 1 ; Function to calculate factorial of N ; Base Case ; Iterate over the range [ 1 , N ] ; Function to calculate NcR ; Driver Code ; Print the result
var box1 = 0 ; var box2 = 0 ; var fact = Array ( 11 ) ; function getProbability ( balls , M ) { factorial ( 10 ) ; box2 = M ; var K = 0 ; for ( var i = 0 ; i < M ; i ++ ) K += balls [ i ] ; if ( K % 2 == 1 ) return 0 ; var all = comb ( K , K / 2 ) ; var validPermutation = validPermutations ( K / 2 , balls , 0 , 0 , M ) ; return validPermutation / all ; } function validPermutations ( n , balls , usedBalls , i , M ) { if ( usedBalls == n ) { return box1 == box2 ? 1 : 0 ; } if ( i >= M ) return 0 ; var res = validPermutations ( n , balls , usedBalls , i + 1 , M ) ; box1 ++ ; for ( var j = 1 ; j <= balls [ i ] ; j ++ ) { if ( j == balls [ i ] ) box2 -- ; var combinations = comb ( balls [ i ] , j ) ; res += combinations * validPermutations ( n , balls , usedBalls + j , i + 1 , M ) ; } box1 -- ; box2 ++ ; return res ; } function factorial ( N ) { fact [ 0 ] = 1 ; for ( var i = 1 ; i <= N ; i ++ ) fact [ i ] = fact [ i - 1 ] * i ; } function comb ( n , r ) { var res = fact [ n ] / fact [ r ] ; res /= fact [ n - r ] ; return res ; } var arr = [ 2 , 1 , 1 ] ; var N = 4 ; var M = arr . length ; document . write ( getProbability ( arr , M ) ) ;
Area of a n | Function to find the area of a regular polygon ; Side and radius cannot be negative ; Area degree converted to radians ; Driver code
function polyarea ( n , r ) { if ( r < 0 && n < 0 ) return - 1 ; var A = ( ( r * r * n ) * Math . sin ( ( 360 / n ) * 3.14159 / 180 ) ) / 2 ; return A ; } var r = 9 , n = 6 ; document . write ( polyarea ( n , r ) . toFixed ( 5 ) ) ;
Check if a line at 45 degree can divide the plane into two equal weight parts | Checking if a plane can be divide by a line at 45 degrees such that weight sum is equal ; Rotating each point by 45 degrees and calculating prefix sum . Also , finding maximum and minimum x coordinates ; storing weight sum upto x - y point ; Finding prefix sum ; Line passes through i , so it neither falls left nor right . ; Driven code
function is_partition_possible ( n , x , y , w ) { let weight_at_x = new Map ( ) ; let max_x = - 2e3 , min_x = 2e3 ; for ( let i = 0 ; i < n ; i ++ ) { let new_x = x [ i ] - y [ i ] ; max_x = Math . max ( max_x , new_x ) ; min_x = Math . min ( min_x , new_x ) ; if ( weight_at_x . has ( new_x ) ) { weight_at_x . set ( new_x , weight_at_x . get ( new_x ) + w [ i ] ) ; } else { weight_at_x . set ( new_x , w [ i ] ) ; } } let sum_till = [ ] ; sum_till . push ( 0 ) ; for ( let s = min_x ; s <= max_x ; s ++ ) { if ( weight_at_x . get ( s ) == null ) sum_till . push ( sum_till [ sum_till . length - 1 ] ) ; else sum_till . push ( sum_till [ sum_till . length - 1 ] + weight_at_x . get ( s ) ) ; } let total_sum = sum_till [ sum_till . length - 1 ] ; let partition_possible = 0 ; for ( let i = 1 ; i < sum_till . length ; i ++ ) { if ( sum_till [ i ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; if ( sum_till [ i - 1 ] == total_sum - sum_till [ i ] ) partition_possible = 1 ; } document . write ( partition_possible == 1 ? " " : " " ) ; } let n = 3 ; let x = [ - 1 , - 2 , 1 ] ; let y = [ 1 , 1 , - 1 ] ; let w = [ 3 , 1 , 4 ] ; is_partition_possible ( n , x , y , w ) ;
Slope of perpendicular to line | Function to find the Slope of other line ; Driver code
function findPCSlope ( m ) { return - 1.0 / m ; } let m = 2.0 ; document . write ( findPCSlope ( m ) ) ;
Program to find area of a Circular Segment | javascript program to find area of segment of a circle ; Function to find area of segment ; Calculating area of sector ; Calculating area of triangle ; Driver Function
let pi = 3.14159 ; function area_of_segment ( radius , angle ) { let area_of_sector = pi * ( radius * radius ) * ( angle / 360 ) ; let area_of_triangle = 1 / 2 * ( radius * radius ) * Math . sin ( ( angle * pi ) / 180 ) ; return area_of_sector - area_of_triangle ; } let radius = 10.0 , angle = 90.0 ; document . write ( " " + area_of_segment ( radius , angle ) + " " ) ; document . write ( " " + area_of_segment ( radius , ( 360 - angle ) ) ) ;
Area of a Circular Sector | Javascript program to find Area of a Sector ; Calculating area of the sector ; Driver code
function SectorArea ( radius , angle ) { if ( angle >= 360 ) document . write ( " " ) ; else { let sector = ( ( 22 * radius * radius ) / 7 ) * ( angle / 360 ) ; document . write ( sector ) ; } } let radius = 9 ; let angle = 60 ; SectorArea ( radius , angle ) ;
Make two numbers equal by multiplying with their prime factors minimum number of times | Javascript program for the above approach ; Everything divides 0 ; Function to calculate total number of prime factor with their prime factor ; Iterate while the number is even ; Reduce to half ; Iterate up to sqrt ( N ) ; Iterate while N has factors of i ; Removing one factor of i ; Function to count the number of factors ; Find the GCD ; Find multiples left in X and Y ; Find prime factor of multiple left in X and Y ; Initialize ans ; Check if it possible to obtain X or not ; Check if it possible to obtain Y or not ; return main ans ; Given Input ; Function Call
function gcd ( a , b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } function PrimeFactor ( N ) { let primef = new Map ( ) ; while ( N % 2 == 0 ) { if ( primef . has ( 2 ) ) { primef . set ( 2 , primef . get ( 2 ) + 1 ) ; } else { primef . set ( 2 , 1 ) ; } N = parseInt ( N / 2 , 10 ) ; } for ( let i = 3 ; i <= Math . sqrt ( N ) ; i ++ ) { while ( N % i == 0 ) { if ( primef . has ( i ) ) { primef . set ( i , primef . get ( i ) + 1 ) ; } else { primef . set ( i , 1 ) ; } N = parseInt ( N / 2 , 10 ) ; } } if ( N > 2 ) { primef [ N ] = 1 ; } return primef ; } function CountToMakeEqual ( X , Y ) { let gcdofXY = gcd ( X , Y ) ; let newX = parseInt ( Y / gcdofXY , 10 ) ; let newY = parseInt ( X / gcdofXY , 10 ) ; let primeX = PrimeFactor ( newX ) ; let primeY = PrimeFactor ( newY ) ; let ans = 0 ; primeX . forEach ( ( values , keys ) => { if ( X % keys != 0 ) { return - 1 ; } ans += primeX . get ( keys ) ; } ) ans += 1 ; primeY . forEach ( ( values , keys ) => { if ( Y % keys != 0 ) { return - 1 ; } ans += primeY . get ( keys ) ; } ) return ans ; } let X = 36 ; let Y = 48 ; let ans = CountToMakeEqual ( X , Y ) ; document . write ( ans ) ;