codeparrot/xlcost-text-to-code huggingface dataset:
Check if N can be represented as sum of distinct powers of 3 | Function to try all permutations of distinct powers ; Base Case ; If the distinct powers sum is obtained ; Otherwise ; If current element not selected in power [ ] ; If current element selected in power [ ] ; Return 1 if any permutation found ; Function to check the N can be represented as the sum of the distinct powers of 3 ; Stores the all distincts powers of three to [ 0 , 15 ] ; Function Call ; print ; Driven Code
function PermuteAndFind ( power , idx , SumSoFar , target ) { if ( idx == power . length ) { if ( SumSoFar == target ) return true ; return false ; } let select = PermuteAndFind ( power , idx + 1 , SumSoFar , target ) ; let notselect = PermuteAndFind ( power , idx + 1 , SumSoFar + power [ idx ] , target ) ; return select || notselect ; } function DistinctPowersOf3 ( N ) { let power = new Array ( 16 ) ; power [ 0 ] = 1 ; for ( let i = 1 ; i < 16 ; i ++ ) power [ i ] = 3 * power [ i - 1 ] ; let found = PermuteAndFind ( power , 0 , 0 , N ) ; if ( found == true ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let N = 91 ; DistinctPowersOf3 ( N ) ;
Check if N can be represented as sum of distinct powers of 3 | Function to check whether the given N can be represented as the sum of the distinct powers of 3 ; Iterate until N is non - zero ; Termination Condition ; Right shift ternary bits by 1 for the next digit ; If N can be expressed as the sum of perfect powers of 3 ; Driver Code
function DistinctPowersOf3 ( N ) { while ( N > 0 ) { if ( N % 3 == 2 ) { document . write ( " " ) ; return ; } N = Math . floor ( N / 3 ) ; } document . write ( " " ) ; } let N = 91 ; DistinctPowersOf3 ( N ) ;
Generate an N | Function to print the permutation of size N with absolute difference of adjacent elements in range [ 2 , 4 ] ; If N is less than 4 ; Check if N is even ; Traverse through odd integers ; Update the value of i ; Traverse through even integers ; Driver Code
function getPermutation ( N ) { if ( N <= 3 ) { document . write ( - 1 ) ; return ; } let i = N ; if ( N % 2 == 0 ) i -- ; while ( i >= 1 ) { document . write ( i + " " ) ; i -= 2 ; } document . write ( 4 + " " + 2 + " " ) ; i = 6 ; while ( i <= N ) { document . write ( i + " " ) ; i += 2 ; } } let N = 9 ; getPermutation ( N ) ;
Count of distinct values till C formed by adding or subtracting A , B , or 0 any number of times | Function to calculate gcd ; Function to find number of possible final values ; Find the gcd of two numbers ; Calculate number of distinct values ; Return values ; Driver Code
function gcd ( A , B ) { if ( B == 0 ) return A ; else return gcd ( B , A % B ) ; } function getDistinctValues ( A , B , C ) { let g = gcd ( A , B ) ; let num_values = C / g ; return num_values ; } let A = 2 ; let B = 3 ; let C = 10 ; document . write ( getDistinctValues ( A , B , C ) ) ;
Find array whose elements are XOR of adjacent elements in given array | Function to reconstruct the array arr [ ] with xor of adjacent elements ; Iterate through each element ; Store the xor of current and next element in arr [ i ] ; Function to print the array ; Inputs ; Length of the array given ; Function call to reconstruct the arr [ ] ; Function call to print arr [ ]
function game_with_number ( arr , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { arr [ i ] = arr [ i ] ^ arr [ i + 1 ] ; } return arr ; } function print ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 10 , 11 , 1 , 2 , 3 ] ; let n = arr . length ; let new_arr = game_with_number ( arr , n ) ; print ( new_arr , n ) ;
Maximize score of same | Function to calculate the score of same - indexed subarrays selected from the arrays a [ ] and b [ ] ; Traverse the current subarray ; Finding the score without reversing the subarray ; Calculating the score of the reversed subarray ; Return the score of subarray ; Function to find the subarray with the maximum score ; Stores the maximum score and the starting and the ending point of subarray with maximum score ; Traverse all the subarrays ; Store the score of the current subarray ; Update the maximum score ; Print the maximum score ; Driver Code
function currSubArrayScore ( a , b , l , r ) { let straightScore = 0 ; let reverseScore = 0 ; for ( let i = l ; i <= r ; i ++ ) { straightScore += a [ i ] * b [ i ] ; reverseScore += a [ r - ( i - l ) ] * b [ i ] ; } return Math . max ( straightScore , reverseScore ) ; } function maxScoreSubArray ( a , b , n ) { let res = 0 , start = 0 , end = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i ; j < n ; j ++ ) { let currScore = currSubArrayScore ( a , b , i , j ) ; if ( currScore > res ) { res = currScore ; start = i ; end = j ; } } } document . write ( res ) ; } let A = [ 13 , 4 , 5 ] ; let B = [ 10 , 22 , 2 ] ; let N = A . length ; maxScoreSubArray ( A , B , N ) ;
Maximize score of same | Function to calculate the score of same - indexed subarrays selected from the arrays a [ ] and b [ ] ; Store the required result ; Iterate in the range [ 0 , N - 1 ] ; Consider the case of odd length subarray ; Update the maximum score ; Expanding the subarray in both directions with equal length so that mid point remains same ; Update both the scores ; Consider the case of even length subarray ; Update both the scores ; Print the result ; Driver Code
function maxScoreSubArray ( a , b , n ) { let res = 0 ; for ( let mid = 0 ; mid < n ; mid ++ ) { let straightScore = a [ mid ] * b [ mid ] , reverseScore = a [ mid ] * a [ mid ] ; let prev = mid - 1 , next = mid + 1 ; res = Math . max ( res , Math . max ( straightScore , reverseScore ) ) ; while ( prev >= 0 && next < n ) { straightScore += ( a [ prev ] * b [ prev ] + a [ next ] * b [ next ] ) ; reverseScore += ( a [ prev ] * b [ next ] + a [ next ] * b [ prev ] ) ; res = Math . max ( res , Math . max ( straightScore , reverseScore ) ) ; prev -- ; next ++ ; } straightScore = 0 ; reverseScore = 0 ; prev = mid - 1 , next = mid ; while ( prev >= 0 && next < n ) { straightScore += ( a [ prev ] * b [ prev ] + a [ next ] * b [ next ] ) ; reverseScore += ( a [ prev ] * b [ next ] + a [ next ] * b [ prev ] ) ; res = Math . max ( res , Math . max ( straightScore , reverseScore ) ) ; prev -- ; next ++ ; } } document . write ( res ) ; } let A = [ 13 , 4 , 5 ] ; let B = [ 10 , 22 , 2 ] ; let N = A . length maxScoreSubArray ( A , B , N ) ;
Length of the smallest subarray with maximum possible sum | Function to find the minimum length of the subarray whose sum is maximum ; Stores the starting and the ending index of the resultant subarray ; Traverse the array until a non - zero element is encountered ; If the array contains only of 0 s ; Traverse the array in reverse until a non - zero element is encountered ; Return the resultant size of the subarray ; Driver Code
function minimumSizeSubarray ( arr , N ) { let i = 0 , j = N - 1 ; while ( i < N && arr [ i ] == 0 ) { i ++ ; } if ( i == N ) return 1 ; while ( j >= 0 && arr [ j ] == 0 ) { j -- ; } return ( j - i + 1 ) ; } let arr = [ 0 , 2 , 0 , 0 , 12 , 0 , 0 , 0 ] ; let N = arr . length ; document . write ( minimumSizeSubarray ( arr , N ) ) ;
Count ways to represent N as XOR of distinct integers not exceeding N | Function to count number of ways to represent N as the Bitwise XOR of distinct integers ; Count number of subsets using above - mentioned formula ; Print the resultant count ; Driver Code
function countXorPartition ( N ) { let a = Math . pow ( 2 , Math . floor ( N - Math . log ( N + 1 ) / Math . log ( 2 ) ) ) ; document . write ( a ) ; } let N = 5 ; countXorPartition ( N ) ;
Count numbers less than N whose modulo with A is equal to B | Function to count numbers less than N , whose modulo with A gives B ; If the value of B at least A ; If the value of B is 0 or not ; Stores the resultant count of numbers less than N ; Update the value of ans ; Print the value of ans ; Driver Code
function countValues ( A , B , C ) { if ( B >= A ) { document . write ( 0 ) ; return ; } if ( B == 0 ) { document . write ( parseInt ( C / A ) ) ; return ; } let ans = parseInt ( C / A ) ; if ( ans * A + B <= C ) { ans ++ ; } document . write ( ans ) ; } let A = 6 , B = 3 , N = 15 ; countValues ( A , B , N ) ;
Maximum sum of a subsequence whose Bitwise AND is non | Function to find the maximum sum of a subsequence whose Bitwise AND is non - zero ; Stores the resultant maximum sum of the subsequence ; Iterate over all the bits ; Stores the sum of array elements whose i - th bit is set ; Traverse the array elements ; If the bit is set , then add its value to the sum ; Update the resultant maximum sum ; Return the maximum sum ; Driver Code
function maximumSum ( arr , N ) { let ans = 0 ; for ( let bit = 0 ; bit < 32 ; bit ++ ) { let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & ( 1 << bit ) ) { sum += arr [ i ] ; } } ans = Math . max ( ans , sum ) ; } return ans ; } let arr = [ 5 , 4 , 1 , 7 , 11 ] ; let N = arr . length ; document . write ( maximumSum ( arr , N ) ) ;
Check if an array can be reduced to at most length K by removal of distinct elements | Function to check if it is possible to reduce the size of the array to K by removing the set of the distinct array elements ; Stores all distinct elements present in the array arr [ ] ; Traverse the given array ; Insert array elements into the set ; Condition for reducing size of the array to at most K ; Driver Code
function maxCount ( arr , N , K ) { let st = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { st . add ( arr [ i ] ) ; } if ( N - st . size <= K ) { document . write ( " " ) ; } else document . write ( " " ) ; } let arr = [ 2 , 2 , 2 , 3 ] ; let K = 3 ; let N = arr . length maxCount ( arr , N , K ) ;
Maximum element present in the array after performing queries to add K to range of indices [ L , R ] | Function to find the max sum after processing q queries ; Store the cumulative sum ; Store the maximum sum ; Iterate over the range 0 to q ; Variables to extract values from vector ; Iterate over the range [ 1 , n ] ; Calculate cumulative sum ; Calculate maximum sum ; Return the maximum sum after q queries ; Stores the size of array and number of queries ; Stores the sum ; Storing input queries ; Function call to find the maximum sum
function max_sum ( a , v , q , n ) { let x = 0 ; let m = Number . MIN_SAFE_INTEGER ; for ( let i = 0 ; i < q ; i ++ ) { let p , q , k ; p = v [ i ] [ 0 ] [ 0 ] ; q = v [ i ] [ 0 ] [ 1 ] ; k = v [ i ] [ 1 ] ; a [ p ] += k ; if ( q + 1 <= n ) a [ q + 1 ] -= k ; } for ( let i = 1 ; i <= n ; i ++ ) { x += a [ i ] ; m = Math . max ( m , x ) ; } return m ; } let n = 10 , q = 3 ; let a = new Array ( n + 5 ) . fill ( 0 ) ; let v = new Array ( q ) . fill ( 0 ) . map ( ( ) => new Array ( 2 ) . fill ( 0 ) . map ( ( ) => new Array ( 2 ) . fill ( 0 ) ) ) ; v [ 0 ] [ 0 ] [ 0 ] = 1 ; v [ 0 ] [ 0 ] [ 1 ] = 5 ; v [ 0 ] [ 1 ] = 3 ; v [ 1 ] [ 0 ] [ 0 ] = 4 ; v [ 1 ] [ 0 ] [ 1 ] = 8 ; v [ 1 ] [ 1 ] = 7 ; v [ 2 ] [ 0 ] [ 0 ] = 6 ; v [ 2 ] [ 0 ] [ 1 ] = 9 ; v [ 2 ] [ 1 ] = 1 ; document . write ( max_sum ( a , v , q , n ) ) ;
Check if a pair of integers from two ranges exists such that their Bitwise XOR exceeds both the ranges | Function to check if there exists any pair ( P , Q ) whose Bitwise XOR is greater than the Bitwise XOR of X and Y ; Stores the Bitwise XOR of X & Y ; Traverse all possible pairs ; If a pair exists ; If a pair is found ; Driver code
function findWinner ( X , Y ) { let playerA = ( X ^ Y ) ; let flag = false ; for ( let i = 1 ; i <= X ; i ++ ) { for ( let j = 1 ; j <= Y ; j ++ ) { let val = ( i ^ j ) ; if ( val > playerA ) { flag = true ; break ; } } if ( flag ) { break ; } } if ( flag ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let A = 2 , B = 4 ; findWinner ( A , B ) ;
Check if a pair of integers from two ranges exists such that their Bitwise XOR exceeds both the ranges | Function to check if there exists any pair ( P , Q ) whose Bitwise XOR is greater than the Bitwise XOR of X and Y ; Check for the invalid condition ; Otherwise , ; Driver Code
function findWinner ( X , Y ) { let first = ( X ^ Y ) ; let second = ( X + Y ) ; if ( first == second ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let A = 2 , B = 4 ; findWinner ( A , B ) ;
Smallest number required to be added to M to make it divisible by N | Function to find the smallest number greater than or equal to N , that is divisible by k ; Function to find the smallest number required to be added to to M to make it divisible by N ; Stores the smallest multiple of N , greater than or equal to M ; Return the result ; Given Input ; Function Call
function findNum ( N , K ) { var rem = ( N + K ) % K ; if ( rem == 0 ) return N ; else return N + K - rem ; } function findSmallest ( M , N ) { var x = findNum ( M , N ) ; return x - M ; } var M = 100 , N = 28 ; document . write ( findSmallest ( M , N ) ) ;
Prefix Factorials of a Prefix Sum Array | Function to find the factorial of prefix sum at every possible index ; Find the prefix sum array ; Stores the factorial of all the element till the sum of array ; Find the factorial array ; Find the factorials of each array element ; Print the resultant array ; Driver Code
function prefixFactorialArray ( A , N ) { for ( let i = 1 ; i < N ; i ++ ) { A [ i ] += A [ i - 1 ] ; } let fact = new Array ( A [ N - 1 ] + 1 ) ; fact [ 0 ] = 1 ; for ( let i = 1 ; i <= A [ N - 1 ] ; i ++ ) { fact [ i ] = i * fact [ i - 1 ] ; } for ( let i = 0 ; i < N ; i ++ ) { A [ i ] = fact [ A [ i ] ] ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length prefixFactorialArray ( arr , N ) ;
Maximum frequency of any array element possible by at most K increments | Function to find the maximum possible frequency of a most frequent element after at most K increment operations ; Sort the input array ; Stores the sum of sliding window and the maximum possible frequency of any array element ; Traverse the array ; Add the current element to the window ; If it is not possible to make the array elements in the window equal ; Update the value of sum ; Increment the value of start ; Update the maximum possible frequency ; Print the frequency of the most frequent array element after K increments ; Driver code
function maxFrequency ( arr , N , K ) { arr . sort ( ( a , b ) => a - b ) ; let start = 0 , end = 0 ; let sum = 0 , res = 0 ; for ( end = 0 ; end < N ; end ++ ) { sum += arr [ end ] ; while ( ( end - start + 1 ) * arr [ end ] - sum > K ) { sum -= arr [ start ] ; start ++ ; } res = Math . max ( res , end - start + 1 ) ; } document . write ( res + " " ) ; } let arr = [ 1 , 4 , 8 , 13 ] ; let N = 4 ; let K = 5 ; maxFrequency ( arr , N , K ) ;
Count pairs ( i , j ) from an array such that i < j and arr [ j ] | Function to count the number of pairs ( i , j ) such that i < j and arr [ i ] - arr [ j ] = X * ( j - i ) ; Stores the count of all such pairs that satisfies the condition . ; Stores count of distinct values of arr [ i ] - x * i ; Iterate over the Map ; Increase count of pairs ; Print the count of such pairs ; Driver Code
function countPairs ( arr , n , x ) { let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] - x * i ) ) { mp . set ( arr [ i ] - x * i , mp . get ( arr [ i ] - x * i ) + 1 ) } else { mp . set ( arr [ i ] - x * i , 1 ) } } for ( let x of mp ) { let n = x [ 1 ] ; count += Math . floor ( ( n * ( n - 1 ) ) / 2 ) ; } document . write ( count ) ; } let n = 6 , x = 3 ; let arr = [ 5 , 4 , 8 , 11 , 13 , 16 ] ; countPairs ( arr , n , x ) ;
Check if a triplet of buildings can be selected such that the third building is taller than the first building and smaller than the second building | Function to check if it is possible to select three buildings that satisfy the given condition ; Stores prefix min array ; Iterate over the range [ 1 , N - 1 ] ; Stores the element from the ending in increasing order ; Iterate until j is greater than or equal to 0 ; If current array element is greater than the prefix min upto j ; Iterate while st is not empty and top element is less than or equal to preMin [ j ] ; Remove the top element ; If st is not empty and top element of the st is less than the current element ; Push the arr [ j ] in st ; If none of the above case satisfy then return " No " ; Input
function recreationalSpot ( arr , N ) { if ( N < 3 ) { return " " ; } var preMin = new Array ( N ) ; preMin [ 0 ] = arr [ 0 ] ; var i ; for ( i = 1 ; i < N ; i ++ ) { preMin [ i ] = Math . min ( preMin [ i - 1 ] , arr [ i ] ) ; } var st = [ ] ; var j ; for ( j = N - 1 ; j >= 0 ; j -- ) { if ( arr [ j ] > preMin [ j ] ) { while ( st . length > 0 && st [ st . length - 1 ] <= preMin [ j ] ) { st . pop ( ) ; } if ( st . length > 0 && st [ st . length - 1 ] < arr [ j ] ) { return " " ; } st . push ( arr [ j ] ) ; } } return " " ; } var arr = [ 4 , 7 , 11 , 5 , 13 , 2 ] ; var size = arr . length ; document . write ( recreationalSpot ( arr , size ) ) ;
Check if a number N can be expressed as the sum of powers of X or not | Function to check if the number N can be expressed as the sum of different powers of X or not ; While n is a positive number ; Find the remainder ; If rem is at least 2 , then representation is impossible ; Divide the value of N by x ; Driver Code
function ToCheckPowerofX ( n , x ) { while ( n > 0 ) { var rem = n % x ; if ( rem >= 2 ) { return false ; } n = n / x ; } return true ; } var N = 10 , X = 3 ; if ( ToCheckPowerofX ( N , X ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Find the maximum between N and the number formed by reversing 32 | Function that obtains the number using said operations from N ; Stores the binary representation of the number N ; Find the binary representation of the number N ; Check for the set bits ; Reverse the string S ; Stores the obtained number ; Calculating the decimal value ; Check for set bits ; Function to find the maximum value between N and the obtained number ; Driver Code
function reverseBin ( N ) { let S = " " ; let i ; for ( i = 0 ; i < 32 ; i ++ ) { if ( N & ( 1 << i ) ) S += ' ' ; else S += ' ' ; } S = S . split ( " " ) . reverse ( ) . join ( " " ) ; let M = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { if ( S [ i ] == ' ' ) M += ( 1 << i ) ; } return M ; } function maximumOfTwo ( N ) { let M = reverseBin ( N ) ; return Math . max ( N , M ) ; } let N = 6 ; document . write ( maximumOfTwo ( N ) ) ;
Sum of Euler Totient Functions obtained for each divisor of N | Function to find the sum of Euler Totient Function of divisors of N ; Return the value of N ; Driver Code
function sumOfDivisors ( N ) { return N ; } let N = 5 ; document . write ( sumOfDivisors ( N ) ) ;
Square root of two Complex Numbers | Function to find the square root of a complex number ; Stores all the square roots ; Stores the first square root ; Push the square root in the ans ; Stores the second square root ; If X2 is not 0 ; Push the square root in the array ans [ ] ; Stores the third square root ; If X3 is greater than 0 ; Push the square root in the array ans [ ] ; Stores the fourth square root ; Push the square root in the array ans [ ] ; Prints the square roots ; Driver Code
function complexRoot ( A , B ) { var ans = [ ] ; var X1 = Math . abs ( Math . sqrt ( ( A + Math . sqrt ( A * A + B * B ) ) / 2 ) ) ; var Y1 = B / ( 2 * X1 ) ; ans . push ( [ X1 , Y1 ] ) ; var X2 = - 1 * X1 ; var Y2 = B / ( 2 * X2 ) ; if ( X2 != 0 ) { ans . push ( [ X2 , Y2 ] ) ; } var X3 = ( A - Math . sqrt ( A * A + B * B ) ) / 2 ; if ( X3 > 0 ) { X3 = Math . abs ( Math . sqrt ( X3 ) ) ; var Y3 = B / ( 2 * X3 ) ; ans . push ( [ X3 , Y3 ] ) ; var X4 = - 1 * X3 ; var Y4 = B / ( 2 * X4 ) ; if ( X4 != 0 ) { ans . push ( [ X4 , Y4 ] ) ; } } document . write ( " " ) ; ans . forEach ( p => { document . write ( p [ 0 ] . toFixed ( 6 ) ) ; if ( p [ 1 ] > 0 ) document . write ( " " ) ; if ( p [ 1 ] ) document . write ( p [ 1 ] . toFixed ( 6 ) + " " ) ; else document . write ( " " ) ; } ) ; } var A = 0 , B = 1 ; complexRoot ( A , B ) ;
Minimum time required to schedule K processes | Function to find minimum required time to schedule all process ; Stores max element from A [ ] ; Find the maximum element ; Stores frequency of each element ; Stores minimum time required to schedule all process ; Count frequencies of elements ; Find the minimum time ; Decrease the value of K ; Increment tmp [ i / 2 ] ; Increment the count ; Return count , if all process are scheduled ; Increment count ; Return the count ; If it is not possible to schedule all process ; Driver Code
function minTime ( A , n , K ) { let max_ability = A [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { max_ability = Math . max ( max_ability , A [ i ] ) ; } let tmp = Array . from ( { length : max_ability + 1 } , ( _ , i ) => 0 ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { tmp [ A [ i ] ] ++ ; } for ( let i = max_ability ; i >= 0 ; i -- ) { if ( tmp [ i ] != 0 ) { if ( tmp [ i ] * i < K ) { K -= ( i * tmp [ i ] ) ; tmp [ ( i / 2 ) ] += tmp [ i ] ; count += tmp [ i ] ; if ( K <= 0 ) { return count ; } } else { if ( K % i != 0 ) { count += Math . floor ( K / i ) + 1 ; } else { count += Math . floor ( K / i ) ; } return count ; } } } return - 1 ; } let arr = [ 3 , 1 , 7 , 2 , 4 ] ; let N = arr . length ; let K = 15 ; document . write ( minTime ( arr , N , K ) ) ;
Minimum length of a rod that can be split into N equal parts that can further be split into given number of equal parts | Function to find GCD of two numbers a and b ; Base Case ; Find GCD recursively ; Function to find the LCM of the resultant array ; Initialize a variable ans as the first element ; Traverse the array ; Update LCM ; Return the minimum length of the rod ; Function to find the minimum length of the rod that can be divided leto N equals parts and each part can be further divided leto arr [ i ] equal parts ; Prlet the result ; Driver Code
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function findlcm ( arr , n ) { let ans = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) ) ; } return ans ; } function minimumRod ( A , N ) { document . write ( N * findlcm ( A , N ) ) ; } let arr = [ 1 , 2 ] ; let N = arr . length ; minimumRod ( arr , N ) ;
Check if N can be represented as sum of positive integers containing digit D at least once | Function to check if N contains digit D in it ; Iterate until N is positive ; Find the last digit ; If the last digit is the same as digit D ; Return false ; Function to check if the value of N can be represented as sum of letegers having digit d in it ; Iterate until N is positive ; Check if N contains digit D or not ; Subtracting D from N ; Return false ; Driver Code
function findDigit ( N , D ) { while ( N > 0 ) { let a = N % 10 ; if ( a == D ) { return true ; } N = Math . floor ( N / 10 ) ; } return false ; } function check ( N , D ) { while ( N > 0 ) { if ( findDigit ( N , D ) == true ) { return true ; } N -= D ; } return false ; } let N = 24 ; let D = 7 ; if ( check ( N , D ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Number of relations that are neither Reflexive nor Irreflexive on a Set | Javascript program for the above approach ; Function to calculate x ^ y modulo 10 ^ 9 + 7 in O ( log y ) ; Stores the result of ( x ^ y ) ; Update x , if it exceeds mod ; If x is divisible by mod ; If y is odd , then multiply x with res ; Divide y by 2 ; Update the value of x ; Return the value of x ^ y ; Function to count the number of relations that are neither reflexive nor irreflexive ; Return the resultant count ; Driver Code
var mod = 1000000007 ; function power ( x , y ) { var res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y % 2 != 0 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } function countRelations ( N ) { document . write ( ( power ( 2 , N ) - 2 ) * power ( 2 , ( N * N ) - N ) ) ; } var N = 2 ; countRelations ( N ) ;