codeparrot/xlcost-text-to-code huggingface dataset:
Minimum and Maximum number of pairs in m teams of n people | javascript program to find minimum and maximum no . of pairs ; Driver code
function MinimumMaximumPairs ( n , m ) { var max_pairs = parseInt ( ( ( n - m + 1 ) * ( n - m ) ) / 2 ) ; var min_pairs = m * parseInt ( ( ( ( n - m ) / m + 1 ) * ( ( n - m ) / m ) ) / 2 ) + parseInt ( Math . ceil ( ( ( n - m ) / ( m ) ) ) ) * ( ( n - m ) % m ) ; document . write ( " " + min_pairs + " " ) ; document . write ( " " + max_pairs ) ; } var n = 5 , m = 2 ; MinimumMaximumPairs ( n , m ) ;
Larger of a ^ b or b ^ a ( a raised to power b or b raised to power a ) | Function to find the greater value ; Driver code
function findGreater ( a , b ) { var x = a * ( Math . log ( ( b ) ) ) ; var y = b * ( Math . log ( ( a ) ) ) ; if ( y > x ) { document . write ( " " ) ; } else if ( y < x ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var a = 3 , b = 5 , c = 2 , d = 4 ; findGreater ( a , b ) ; findGreater ( c , d ) ;
Expressing a fraction as a natural number under modulo ' m ' | javascript implementation of the approach ; Function to return the GCD of given numbers ; Recursive function to return ( x ^ n ) % m ; Function to return the fraction modulo mod ; ( b ^ m - 2 ) % m ; Final answer ; Driver code
var m = 100000007 ; function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function modexp ( x , n ) { if ( n == 0 ) { return 1 ; } else if ( n % 2 == 0 ) { return modexp ( ( x * x ) % m , n / 2 ) ; } else { return ( x * modexp ( ( x * x ) % m , ( n - 1 ) / 2 ) % m ) ; } } function getFractionModulo ( a , b ) { var c = gcd ( a , b ) ; a = a / c ; b = b / c ; var d = modexp ( b , m - 2 ) ; var ans = ( ( a % m ) * ( d % m ) ) % m ; return ans ; } var a = 2 , b = 6 ; document . write ( getFractionModulo ( a , b ) ) ;
Find sum of a number and its maximum prime factor | Function to return the sum of n and it 's largest prime factor ; Initialise maxPrime to - 1. ; n must be odd at this point , thus skip the even numbers and iterate only odd numbers ; This condition is to handle the case when n is a prime number greater than 2 ; finally return the sum . ; Driver Code
function maxPrimeFactors ( n ) { var num = n ; var maxPrime = - 1 ; while ( n % 2 == 0 ) { maxPrime = 2 ; n = parseInt ( n / 2 ) ; } for ( var i = 3 ; i <= parseInt ( Math . sqrt ( n ) ) ; i += 2 ) { while ( n % i == 0 ) { maxPrime = i ; n = parseInt ( n / i ) ; } } if ( n > 2 ) { maxPrime = n ; } var sum = maxPrime + num ; return sum ; } var n = 19 ; document . write ( maxPrimeFactors ( n ) ) ;
Largest number less than N with digit sum greater than the digit sum of N | Function to return the sum of the digits of n ; Loop for each digit of the number ; Function to return the greatest number less than n such that the sum of its digits is greater than the sum of the digits of n ; Starting from n - 1 ; Check until 1 ; If i satisfies the given condition ; If the condition is not satisfied ; Driver code
function sumOfDigits ( n ) { var res = 0 ; while ( n > 0 ) { res += n % 10 ; n = parseInt ( n / 10 ) ; } return res ; } function findNumber ( n ) { var i = n - 1 ; while ( i > 0 ) { if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) return i ; i -- ; } return - 1 ; } var n = 824 ; document . write ( findNumber ( n ) ) ;
Find the Nth term of the series 14 , 28 , 20 , 40 , ... . . | Function to find the N - th term ; initializing the 1 st number ; loop from 2 nd term to nth term ; if i is even , double the previous number ; if i is odd , subtract 8 from previous number ; Driver Code
function findNth ( N ) { let b = 14 ; for ( let i = 2 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) b = b * 2 ; else b = b - 8 ; } return b ; } N = 6 ; document . write ( findNth ( N ) ) ;
Problem of 8 Neighbours of an element in a 2 | Dimension of Array ; Count of 1 s ; Counting all neighbouring 1 s ; Comparing the number of neighbouring 1 s with given ranges ; Copying changes to the main matrix ; Driver code ; Function call to calculate the resultant matrix after ' K ' iterations . ; Printing Result
let N = 4 ; function predictMatrix ( arr , range1a , range1b , range0a , range0b , K , b ) { let c = 0 ; while ( K != 0 ) { K -- ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { c = 0 ; if ( i > 0 && arr [ i - 1 ] [ j ] == 1 ) c ++ ; if ( j > 0 && arr [ i ] [ j - 1 ] == 1 ) c ++ ; if ( i > 0 && j > 0 && arr [ i - 1 ] [ j - 1 ] == 1 ) c ++ ; if ( i < N - 1 && arr [ i + 1 ] [ j ] == 1 ) c ++ ; if ( j < N - 1 && arr [ i ] [ j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j < N - 1 && arr [ i + 1 ] [ j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j > 0 && arr [ i + 1 ] [ j - 1 ] == 1 ) c ++ ; if ( i > 0 && j < N - 1 && arr [ i - 1 ] [ j + 1 ] == 1 ) c ++ ; if ( arr [ i ] [ j ] == 1 ) { if ( c >= range1a && c <= range1b ) b [ i ] [ j ] = 1 ; else b [ i ] [ j ] = 0 ; } if ( arr [ i ] [ j ] == 0 ) { if ( c >= range0a && c <= range0b ) b [ i ] [ j ] = 1 ; else b [ i ] [ j ] = 0 ; } } } for ( let k = 0 ; k < N ; k ++ ) for ( let m = 0 ; m < N ; m ++ ) arr [ k ] [ m ] = b [ k ] [ m ] ; } } let arr = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 1 , 0 , 1 ] ] ; let range1a = 2 , range1b = 2 ; let range0a = 2 , range0b = 3 ; let K = 3 ; let b = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { b [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { b [ i ] [ j ] = 0 ; } } predictMatrix ( arr , range1a , range1b , range0a , range0b , K , b ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( " " ) ; for ( let j = 0 ; j < N ; j ++ ) document . write ( b [ i ] [ j ] + " " ) ; }
Number of moves required to guess a permutation . | Function that returns the required moves ; Final move ; Driver code
function countMoves ( n ) { let ct = 0 ; for ( let i = 1 ; i <= n ; i ++ ) ct += i * ( n - i ) ; ct += n ; return ct ; } let n = 3 ; document . write ( countMoves ( n ) ) ;
Count number of triplets ( a , b , c ) such that a ^ 2 + b ^ 2 = c ^ 2 and 1 <= a <= b <= c <= n | Function to return an Array containing all the perfect squares upto n ; While current perfect square is less than or equal to n ; Function to return the count of triplet ( a , b , c ) pairs such that a ^ 2 + b ^ 2 = c ^ 2 and 1 <= a <= b <= c <= n ; Vector of perfect squares upto n ^ 2 ; Since , a ^ 2 + b ^ 2 = c ^ 2 ; If c < a or bSquare is not a perfect square ; If triplet pair ( a , b , c ) satisfy the given condition ; Driver code
function getPerfectSquares ( n ) { var perfectSquares = [ ] ; var current = 1 , i = 1 ; while ( current <= n ) { perfectSquares . push ( current ) ; current = Math . pow ( ++ i , 2 ) ; } return perfectSquares ; } function countTriplets ( n ) { var perfectSquares = getPerfectSquares ( Math . pow ( n , 2 ) ) ; var count = 0 ; for ( var a = 1 ; a <= n ; a ++ ) { var aSquare = Math . pow ( a , 2 ) ; for ( var i = 0 ; i < perfectSquares . length ; i ++ ) { var cSquare = perfectSquares [ i ] ; var bSquare = Math . abs ( cSquare - aSquare ) ; var b = Math . sqrt ( bSquare ) ; var c = Math . sqrt ( cSquare ) ; if ( c < a || ! perfectSquares . includes ( bSquare ) ) continue ; if ( ( b >= a ) && ( b <= c ) && ( aSquare + bSquare == cSquare ) ) count ++ ; } } return count ; } var n = 10 ; document . write ( countTriplets ( n ) ) ;
Count Numbers with N digits which consists of even number of 0 ’ s | Function to count Numbers with N digits which consists of odd number of 0 's ; Driver code
function countNumbers ( N ) { return ( Math . pow ( 10 , N ) - 1 ) - ( Math . pow ( 10 , N ) - Math . pow ( 8 , N ) ) / 2 ; } var n = 2 ; document . write ( countNumbers ( n ) ) ;
Find determinant of matrix generated by array rotation | Java script program for finding determinant of generated matrix ; Function to calculate determinant ; Driver code
let N = 3 ; function calcDeterminant ( arr ) { let determinant = 0 ; for ( let i = 0 ; i < N ; i ++ ) { determinant += Math . pow ( arr [ i ] , 3 ) ; } determinant -= 3 * arr [ 0 ] * arr [ 1 ] * arr [ 2 ] ; return determinant ; } let arr = [ 4 , 5 , 3 ] ; document . write ( calcDeterminant ( arr ) ) ;
Minimum elements to be added in a range so that count of elements is divisible by K | Javascript implementation of the approach ; Total elements in the range ; If total elements are already divisible by k ; Value that must be added to count in order to make it divisible by k ; Driver code
function minimumMoves ( k , l , r ) { let count = r - l + 1 ; if ( count % k == 0 ) return 0 ; return ( k - ( count % k ) ) ; } let k = 3 , l = 10 , r = 10 ; document . write ( minimumMoves ( k , l , r ) ) ;
Sum of all even numbers in range L and R | Function to return the sum of all natural numbers ; Function to return sum of even numbers in range L and R ; driver program
function sumNatural ( n ) { let sum = Math . floor ( n * ( n + 1 ) ) ; return sum ; } function sumEven ( l , r ) { return sumNatural ( Math . floor ( r / 2 ) ) - sumNatural ( Math . floor ( l - 1 ) / 2 ) ; } let l = 2 , r = 5 ; document . write ( " " + sumEven ( l , r ) ) ;
Check if N is divisible by a number which is composed of the digits from the set { A , B } | Function to check whether n is divisible by a number whose digits are either a or b ; Base condition ; Recursive call ; Check for all numbers beginning with ' a ' or ' b ' ; Driver code
function isDivisibleRec ( x , a , b , n ) { if ( x > n ) return false ; if ( n % x == 0 ) return true ; return ( isDivisibleRec ( x * 10 + a , a , b , n ) || isDivisibleRec ( x * 10 + b , a , b , n ) ) ; } function isDivisible ( a , b , n ) { return isDivisibleRec ( a , a , b , n ) || isDivisibleRec ( b , a , b , n ) ; } let a = 3 , b = 5 , n = 53 ; if ( isDivisible ( a , b , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Minimum number of moves required to reach the destination by the king in a chess board | function to Find the minimum number of moves required to reach the destination by the king in a chess board ; Minimum number of steps ; While the king is not in the same row or column as the destination ; Go up ; Go down ; Go left ; Go right ; Driver code
function MinSteps ( SourceX , SourceY , DestX , DestY ) { document . write ( Math . max ( Math . abs ( SourceX - DestX ) , Math . abs ( SourceY - DestY ) ) + " " ) ; while ( ( SourceX != DestX ) || ( SourceY != DestY ) ) { if ( SourceX < DestX ) { document . write ( ' ' ) ; SourceX ++ ; } if ( SourceX > DestX ) { document . write ( ' ' ) ; SourceX -- ; } if ( SourceY > DestY ) { document . write ( ' ' ) ; SourceY -- ; } if ( SourceY < DestY ) { document . write ( ' ' ) ; SourceY ++ ; } document . write ( " " ) ; } } let sourceX = 4 , sourceY = 4 ; let destinationX = 7 , destinationY = 0 ; MinSteps ( sourceX , sourceY , destinationX , destinationY ) ;
Element equal to the sum of all the remaining elements | Function to find the element ; sum is use to store sum of all elements of array ; iterate over all elements ; Driver code
function findEle ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] == sum - arr [ i ] ) return arr [ i ] ; return - 1 ; } var arr = [ 1 , 2 , 3 , 6 ] ; var n = arr . length ; document . write ( findEle ( arr , n ) ) ;
Sum of all natural numbers in range L to R | Function to return the sum of all natural numbers ; Function to return the sum of all numbers in range L and R ; Driver Code
function sumNatural ( n ) { sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } function suminRange ( l , r ) { return sumNatural ( r ) - sumNatural ( l - 1 ) ; } let l = 2 ; let r = 5 ; document . write ( " " + suminRange ( l , r ) ) ;
Check if a large number is divisible by 75 or not | check divisibleBy3 ; to store sum of Digit ; traversing through each digit ; summing up Digit ; check if sumOfDigit is divisibleBy3 ; check divisibleBy25 ; if a single digit number ; length of the number ; taking the last two digit ; checking if the lastTwo digit is divisibleBy25 ; Function to check divisibleBy75 or not ; check if divisibleBy3 and divisibleBy25 ; Drivers code ; divisible ; if divisibleBy75
function divisibleBy3 ( number ) { let sumOfDigit = 0 ; for ( let i = 0 ; i < number . length ; i ++ ) sumOfDigit += number [ i ] - ' ' ; if ( sumOfDigit % 3 == 0 ) return true ; return false ; } function divisibleBy25 ( number ) { if ( number . length < 2 ) return false ; let length = number . length ; let lastTwo = ( number [ length - 2 ] - ' ' ) * 10 + ( number [ length - 1 ] - ' ' ) ; if ( lastTwo % 25 == 0 ) return true ; return false ; } function divisibleBy75 ( number ) { if ( divisibleBy3 ( number ) && divisibleBy25 ( number ) ) return true ; return false ; } let number = " " ; let divisible = divisibleBy75 ( number ) ; if ( divisible ) document . write ( " " ) ; else document . write ( " " ) ;
Find the other number when LCM and HCF given | Function that will calculates the zeroes at the end ; Driver code ; Calling function .
function otherNumber ( A , Lcm , Hcf ) { return ( Lcm * Hcf ) / A ; } let A = 8 , Lcm = 8 , Hcf = 1 ; let result = otherNumber ( A , Lcm , Hcf ) ; document . write ( " " + result ) ;
Minimum numbers ( smaller than or equal to N ) with sum S | Function to find the minimum numbers required to get to S ; Driver Code
function minimumNumbers ( n , s ) { if ( s % n ) return parseInt ( s / n ) + 1 ; else return parseInt ( s / n ) ; } let n = 5 ; let s = 11 ; document . write ( minimumNumbers ( n , s ) ) ;
Sum of multiples of A and B less than N | JavaScript program to find the sum of all multiples of A and B below N ; Function to find sum of AP series ; Number of terms ; Function to find the sum of all multiples of A and B below N ; Since , we need the sum of multiples less than N ; common factors of A and B ; Driver code
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function sumAP ( n , d ) { n = parseInt ( n / d ) ; return ( n ) * ( 1 + n ) * d / 2 ; } function sumMultiples ( A , B , n ) { n -- ; common = parseInt ( ( A * B ) / __gcd ( A , B ) ) ; return sumAP ( n , A ) + sumAP ( n , B ) - sumAP ( n , common ) ; } let n = 100 ; let A = 5 ; let B = 10 ; document . write ( " " + sumMultiples ( A , B , n ) ) ;
Check if a prime number can be expressed as sum of two Prime Numbers | Function to check whether a number is prime or not ; Function to check if a prime number can be expressed as sum of two Prime Numbers ; If the number is prime , and number - 2 is also prime ; Driver code
function isPrime ( n ) { if ( n <= 1 ) return false ; for ( var i = 2 ; i <= parseInt ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function isPossible ( N ) { if ( isPrime ( N ) && isPrime ( N - 2 ) ) return true ; else return false ; } var n = 13 ; if ( isPossible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count pairs from two arrays whose modulo operation yields K | Function to return the total pairs of elements whose modulo yield K ; set is used to avoid duplicate pairs ; check which element is greater and proceed according to it ; check if modulo is equal to K ; return size of the set ; Driver code
function totalPairs ( arr1 , arr2 , K , n , m ) { var s = new Set ( ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { if ( arr1 [ i ] > arr2 [ j ] ) { if ( arr1 [ i ] % arr2 [ j ] == K ) s . add ( [ arr1 [ i ] , arr2 [ j ] ] ) ; } else { if ( arr2 [ j ] % arr1 [ i ] == K ) s . add ( [ arr2 [ j ] , arr1 [ i ] ] ) ; } } } return s . size ; } var arr1 = [ 8 , 3 , 7 , 50 ] ; var arr2 = [ 5 , 1 , 10 , 4 ] ; var K = 3 ; var n = arr1 . length ; var m = arr2 . length ; document . write ( totalPairs ( arr1 , arr2 , K , n , m ) ) ;
Largest sub | function to return the length of the largest sub - array of an array every element of whose is a perfect square ; if both a and b are equal then arr [ i ] is a perfect square ; Driver code
function contiguousPerfectSquare ( arr , n ) { var a ; var b ; var current_length = 0 ; var max_length = 0 ; for ( var i = 0 ; i < n ; i ++ ) { b = ( Math . sqrt ( arr [ i ] ) ) ; a = parseInt ( b ) ; if ( a == b ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } var arr = [ 9 , 75 , 4 , 64 , 121 , 25 ] ; var n = arr . length ; document . write ( contiguousPerfectSquare ( arr , n ) ) ;
Count pairs of numbers from 1 to N with Product divisible by their Sum | Function to count pairs ; variable to store count ; Generate all possible pairs such that 1 <= x < y < n ; Driver code
function countPairs ( n ) { let count = 0 ; for ( let x = 1 ; x < n ; x ++ ) { for ( let y = x + 1 ; y <= n ; y ++ ) { if ( ( y * x ) % ( y + x ) == 0 ) count ++ ; } } return count ; } let n = 15 ; document . write ( countPairs ( n ) ) ;
Find the index of the left pointer after possible moves in the array | Function that returns the index of the left pointer ; There 's only one element  in the array ; Initially both are at end ; Driver code
function getIndex ( a , n ) { if ( n == 1 ) return 0 ; let ptrL = 0 , ptrR = n - 1 , sumL = a [ 0 ] , sumR = a [ n - 1 ] ; while ( ptrR - ptrL > 1 ) { if ( sumL < sumR ) { ptrL ++ ; sumL += a [ ptrL ] ; } else if ( sumL > sumR ) { ptrR -- ; sumR += a [ ptrR ] ; } else { break ; } } return ptrL ; } let a = [ 2 , 7 , 9 , 8 , 7 ] ; let n = a . length ; document . write ( getIndex ( a , n ) ) ;
Find the position of the last removed element from the array | Function to find the original position of the element which will be removed last ; Take ceil of every number ; Since position is index + 1 ; Driver code
function getPosition ( a , n , m ) { for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = ( a [ i ] / m + ( a [ i ] % m ) ) ; } let ans = - 1 , max = - 1 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( max < a [ i ] ) { max = a [ i ] ; ans = i ; } } return ans + 1 ; } let a = [ 2 , 5 , 4 ] ; let n = a . length ; let m = 2 ; document . write ( getPosition ( a , n , m ) ) ;
Find the value of f ( n ) / f ( r ) * f ( n | Function to find value of given F ( n ) ; iterate over n ; calculate result ; return the result ; Driver code
function calcFunction ( n , r ) { var finalDenominator = 1 ; var mx = Math . max ( r , n - r ) ; for ( var i = mx + 1 ; i <= n ; i ++ ) { var denominator = Math . pow ( i , i ) ; var numerator = Math . pow ( i - mx , i - mx ) ; finalDenominator = ( finalDenominator * denominator ) / numerator ; } return finalDenominator ; } var n = 6 , r = 2 ; document . write ( " " + calcFunction ( n , r ) ) ;
Check if the array has an element which is equal to sum of all the remaining elements | Function to check if such element exists or not ; Storing frequency in map ; Stores the sum ; Traverse the array and count the array elements ; Only possible if sum is even ; If half sum is available ; Driver Code
function isExists ( a , n ) { let freq = new Map ( ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { freq . set ( a [ i ] , freq . get ( a [ i ] ) == null ? 0 : freq . get ( a [ i ] ) + 1 ) ; sum += a [ i ] ; } if ( sum % 2 == 0 ) { if ( freq . get ( sum / 2 ) != null ) return true ; } return false ; } let a = [ 5 , 1 , 2 , 2 ] ; let n = a . length ; if ( isExists ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Print all numbers less than N with at | Javascript program to print all the numbers less than N which have at most 2 unique digits ; Function to generate all possible numbers ; If the number is less than n ; If the number exceeds ; Check if it is not the same number ; Function to print all numbers ; All combination of digits ; Print all numbers ; Driver code
let st = new Set ( ) ; function generateNumbers ( n , num , a , b ) { if ( num > 0 && num < n ) st . add ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } function printNumbers ( n ) { for ( let i = 0 ; i <= 9 ; i ++ ) for ( let j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; document . write ( " " ) ; document . write ( Array . from ( st ) . sort ( function ( a , b ) { return a - b ; } ) . join ( " " ) ) ; st . clear ( ) ; } let n = 12 ; printNumbers ( n ) ;
Smallest prime number missing in an array | this store all prime number upto 10 ^ 5 this function find all prime ; use sieve to find prime ; if number is prime then store it in prime vector ; Function to find the smallest prime missing ; first of all find all prime ; now store all number as index of freq arr so that we can improve searching ; now check for each prime ; Driver code ; find smallest prime which is not present
function findPrime ( MAX ) { let pm = new Array ( MAX + 1 ) ; pm . fill ( true ) ; pm [ 0 ] = pm [ 1 ] = false ; for ( let i = 2 ; i <= MAX ; i ++ ) if ( pm [ i ] ) for ( let j = 2 * i ; j <= MAX ; j += i ) pm [ j ] = false ; let prime = new Array ( ) ; for ( let i = 0 ; i <= MAX ; i ++ ) if ( pm [ i ] ) prime . push ( i ) ; return prime ; } function findSmallest ( arr , n ) { let MAX = arr . sort ( ( A , B ) => A - B ) . reverse ( ) [ 0 ] ; let prime = findPrime ( MAX ) ; let s = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; let ans = - 1 ; for ( let i = 0 ; i < prime . length ; i ++ ) { if ( ! s . has ( prime [ i ] ) ) { ans = prime [ i ] ; break ; } } return ans ; } let arr = [ 3 , 0 , 1 , 2 , 7 ] ; let n = arr . length ; if ( findSmallest ( arr , n ) == - 1 ) document . write ( " " ) ; else document . write ( findSmallest ( arr , n ) ) ;
Find the number after successive division | Function to find the number ; Driver Code
function findNum ( div , rem , N ) { var num = rem [ N - 1 ] ; for ( var i = N - 2 ; i >= 0 ; i -- ) { num = num * div [ i ] + rem [ i ] ; } return num ; } var div = [ 8 , 3 ] ; var rem = [ 2 , 2 ] ; var N = div . length ; document . write ( findNum ( div , rem , N ) ) ;
Program to find the profit or loss when CP of N items is equal to SP of M items | Function to calculate Profit or loss ; Driver Code
function profitLoss ( N , M ) { if ( N == M ) document . write ( " " ) ; else { var result = 0.0 ; result = ( Math . abs ( N - M ) ) / M ; if ( N - M < 0 ) document . write ( " " + result . toFixed ( 6 ) * 100 + " " ) ; else document . write ( " " + result . toFixed ( 6 ) * 100 + " " ) ; } } var N = 8 , M = 9 ; profitLoss ( N , M ) ;