codeparrot/xlcost-text-to-code huggingface dataset:
Make the Array sum 0 by using either ceil or floor on each element | Java program for the above approach ; Function to modify the array element such that the sum is close to 0 ; Stores the modified elements ; Stores the sum of array element ; Stores minimum size of the array ; Traverse the array and find the sum ; If sum is positive ; Find the minimum number of elements that must be changed ; Iterate until M elements are modified or the array end ; Update the current array elements to its floor ; Print the resultant array ; Driver Code
import java . util . * ; class GFG { static void setSumtoZero ( double arr [ ] , int N ) { int [ ] A = new int [ N ] ; int sum = 0 ; int m = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { sum += Math . ceil ( arr [ i ] ) ; A [ i ] = ( int ) Math . ceil ( arr [ i ] ) ; } if ( sum > 0 ) { m = Math . min ( sum , N ) ; for ( int i = 0 ; i < N && m > 0 ; i ++ ) { A [ i ] = ( int ) Math . floor ( arr [ i ] ) ; if ( A [ i ] != Math . floor ( arr [ i ] ) ) m -- ; } } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( A [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { double arr [ ] = { - 2 , - 2 , 4.5 } ; int N = arr . length ; setSumtoZero ( arr , N ) ; } }
Find first undeleted integer from K to N in given unconnected Graph after performing Q queries | Java program for the above approach ; Function to perform th Get operation of disjoint set union ; Function to perform the union operation of dijoint set union ; Update the graph [ a ] as b ; Function to perform given queries on set of vertices initially not connected ; Stores the vertices ; Mark every vertices rightmost vertex as i ; Traverse the queries array ; Check if it is first type of the givan query ; Get the parent of a ; Print the answer for the second query ; Driver Code
class GFG { public static int Get ( int [ ] graph , int a ) { return graph [ a ] = ( graph [ a ] == a ? a : Get ( graph , graph [ a ] ) ) ; } public static void Union ( int [ ] graph , int a , int b ) { a = Get ( graph , a ) ; b = Get ( graph , b ) ; graph [ a ] = b ; } public static void Queries ( int [ ] [ ] queries , int N , int M ) { int [ ] graph = new int [ N + 2 ] ; for ( int i = 1 ; i <= N + 1 ; i ++ ) { graph [ i ] = i ; } for ( int [ ] query : queries ) { if ( query [ 0 ] == 1 ) { Union ( graph , query [ 1 ] , query [ 1 ] + 1 ) ; } else { int a = Get ( graph , query [ 1 ] ) ; if ( a == N + 1 ) System . out . print ( - 1 ) ; else System . out . print ( graph [ a ] + " ▁ " ) ; } } } public static void main ( String args [ ] ) { int N = 5 ; int [ ] [ ] queries = { { 2 , 1 } , { 1 , 1 } , { 2 , 1 } , { 2 , 3 } } ; int Q = queries . length ; Queries ( queries , N , Q ) ; } }
Finding the Nth term in a sequence formed by removing digit K from natural numbers | Java implementation for the above approach ; Denotes the digit place ; Method to convert any number to binary equivalent ; denotes the current digits place ; If current digit is >= K increment its value by 1 ; Else add the digit as it is ; Move to the next digit ; Driver code
import java . io . * ; class GFG { static long convertToBase9 ( long n ) { long ans = 0 ; long a = 1 ; while ( n > 0 ) { ans += ( a * ( n % 9 ) ) ; a *= 10 ; n /= 9 ; } return ans ; } static long getNthnumber ( long base9 , long K ) { long ans = 0 ; long a = 1 ; while ( base9 > 0 ) { int cur = ( int ) ( base9 % 10 ) ; if ( cur >= K ) { ans += a * ( cur + 1 ) ; } else { ans += a * cur ; } base9 /= 10 ; a *= 10 ; } return ans ; } public static void main ( String [ ] args ) { long N = 10 , K = 1 ; long base9 = convertToBase9 ( N ) ; System . out . println ( getNthnumber ( base9 , K ) ) ; } }
Check if given array can be rearranged such that mean is equal to median | Java program for the above approach ; Function to return true or false if size of array is odd ; To prevent overflow ; If element is greater than mid , then it can only be present in right subarray ; If element is smaller than mid , then it can only be present in left subarray ; Else the element is present at the middle then return 1 ; when element is not present in array then return 0 ; Function to return true or false if size of array is even ; Calculating Candidate Median ; If Candidate Median if greater than Mean then decrement j ; If Candidate Median if less than Mean then increment i ; If Candidate Median if equal to Mean then return 1 ; when No candidate found for mean ; Function to return true if Mean can be equal to any candidate median otherwise return false ; Calculating Mean ; If N is Odd ; If N is even ; Driver Code
import java . io . * ; public class GFG { static boolean binarySearch ( float [ ] arr , int size , float key ) { int low = 0 , high = size - 1 , mid ; while ( low <= high ) { mid = low + ( high - low ) / 2 ; if ( key > arr [ mid ] ) low = mid + 1 ; else if ( key < arr [ mid ] ) high = mid - 1 ; else return true ; } return false ; } static boolean twoPointers ( float [ ] arr , int N , float mean ) { int i = 0 , j = N - 1 ; while ( i < j ) { float temp = ( arr [ i ] + arr [ j ] ) / 2 ; if ( temp > mean ) j -- ; else if ( temp < mean ) i ++ ; else return true ; } return false ; } static boolean checkArray ( float [ ] arr , int N ) { float sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; float mean = sum / N ; if ( ( N & 1 ) != 0 ) return binarySearch ( arr , N , mean ) ; else return twoPointers ( arr , N , mean ) ; } public static void main ( String [ ] args ) { float [ ] arr = { 1.0f , 3.0f , 6.0f , 9.0f , 12.0f , 32.0f } ; int N = arr . length ; if ( checkArray ( arr , N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Count of distinct integers belonging to first N terms of at least one of given GPs | Java program for the above approach ; Function to find the count of distinct integers that belong to the first N terms of at least one of them is GP ; Stores the integers that occur in GPs in a set data - structure ; Stores the current integer of the first GP ; Iterate first N terms of first GP ; Insert the ith term of GP in S ; Stores the current integer of the second GP ; Iterate first N terms of second GP ; Return Answer ; Driver Code
import java . util . * ; class GFG { static int UniqueGeometricTerms ( int N , int a1 , int r1 , int a2 , int r2 ) { HashSet < Integer > S = new HashSet < Integer > ( ) ; int p1 = a1 ; for ( int i = 0 ; i < N ; i ++ ) { S . add ( p1 ) ; p1 = ( p1 * r1 ) ; } int p2 = a2 ; for ( int i = 0 ; i < N ; i ++ ) { S . add ( p2 ) ; p2 = ( p2 * r2 ) ; } return S . size ( ) ; } public static void main ( String [ ] args ) { int N = 5 ; int a1 = 3 , r1 = 2 , a2 = 2 , r2 = 3 ; System . out . print ( UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) ) ; } }
Minimize operations to make all array elements | Java program for the above approach ; Function to find minimum the number of operations required to make all the array elements to - 1 ; Stores the array elements with their corresponding indices ; Push the array element and it 's index ; Sort the elements according to it 's first value ; Stores the minimum number of operations required ; Traverse until vp is not empty ; Stores the first value of vp ; Stores the second value of vp ; Update the minCnt ; Pop the back element from the vp until the first value is same as val and difference between indices is less than K ; Return the minCnt ; Driver Code
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int minOperations ( int arr [ ] , int N , int K ) { Vector < pair > vp = new Vector < pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { vp . add ( new pair ( arr [ i ] , i ) ) ; } Collections . sort ( vp , ( a , b ) -> a . first - b . first ) ; int minCnt = 0 ; while ( ! vp . isEmpty ( ) ) { int val , ind ; val = vp . get ( vp . size ( ) - 1 ) . first ; ind = vp . get ( vp . size ( ) - 1 ) . second ; minCnt ++ ; while ( ! vp . isEmpty ( ) && vp . get ( vp . size ( ) - 1 ) . first == val && ind - vp . get ( vp . size ( ) - 1 ) . second + 1 <= K ) vp . remove ( vp . size ( ) - 1 ) ; } return minCnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 18 , 11 , 18 , 11 , 18 } ; int K = 3 ; int N = arr . length ; System . out . print ( minOperations ( arr , N , K ) ) ; } }
Find array sum after incrementing by K adjacent elements of every positive element M times | Java program for the above approach ; Function to find the nearest non - zero element in the left direction ; Stores the index of the first element greater than 0 from the right side ; Traverse the array in the range [ 1 , N ] ; Check arr [ i ] is greater than 0 ; Update the value of L ; Traverse the array from the left side ; Check arr [ i ] is greater than 0 ; Update the value of L ; Update the value of steps [ i ] ; Function to find the nearest non - zero element in the right direction ; Stores the index of the first element greater than 0 from the left side ; Traverse the array from the left side ; Check arr [ i ] is greater than 0 ; Update the value of R ; Traverse the array from the right side ; Check arr [ i ] is greater than 0 ; Update the value of R ; Update the value of steps [ i ] ; Function to find the sum of the array after the given operation M times ; Stores the distance of the nearest non zero element . ; Stores sum of the initial array arr [ ] ; Traverse the array from the left side ; Update the value of sum ; Print the total sum of the array ; Driver Code
import java . util . * ; class GFG { static void nearestLeft ( int arr [ ] , int N , int [ ] steps ) { int L = - N ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { L = - ( N - i ) ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { L = i ; } steps [ i ] = i - L ; } } static void nearestRight ( int arr [ ] , int N , int [ ] steps ) { int R = 2 * N ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { R = N + i ; break ; } } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { R = i ; } steps [ i ] = Math . min ( steps [ i ] , R - i ) ; } } static int accumulate ( int [ ] arr , int start , int end ) { int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) sum += arr [ i ] ; return sum ; } static int findSum ( int arr [ ] , int N , int M , int K ) { int [ ] steps = new int [ N ] ; int sum = accumulate ( arr , 0 , N ) ; if ( sum == 0 ) { return 0 ; } nearestLeft ( arr , N , steps ) ; nearestRight ( arr , N , steps ) ; for ( int i = 0 ; i < N ; i ++ ) sum += 2 * K * Math . max ( 0 , M - steps [ i ] ) ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 0 , 1 , 0 , 0 } ; int N = arr . length ; int M = 2 ; int K = 1 ; System . out . print ( findSum ( arr , N , M , K ) ) ; } }
Count of pairs in given range having their ratio equal to ratio of product of their digits | Java program for the above approach ; Function to find the product of digits of the given number ; Function to find the count of pairs ( a , b ) such that a : b = ( product ofdigits of a ) : ( product of digits of b ) ; Stores the count of the valid pairs ; Loop to iterate over all unordered pairs ( a , b ) ; Stores the product of digits of a ; Stores the product of digits of b ; If x != 0 and y != 0 and a : b is equivalent to x : y ; Increment valid pair count ; Return Answer ; Driver code ; Function Call
class GFG { public static int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } public static int countPairs ( int L , int R ) { int cntPair = 0 ; for ( int a = L ; a <= R ; a ++ ) { for ( int b = a + 1 ; b <= R ; b ++ ) { int x = getProduct ( a ) ; int y = getProduct ( b ) ; if ( x != 0 && y != 0 && ( a * y ) == ( b * x ) ) { cntPair ++ ; } } } return cntPair ; } public static void main ( String args [ ] ) { int L = 1 ; int R = 100 ; System . out . println ( countPairs ( L , R ) ) ; } }
Find numbers in range [ L , R ] that are coprime with given Array elements | Java program for the above approach ; Function to find all the elements in the range [ L , R ] which are co prime with all array elements ; Store all the divisors of array element in S ; Find the divisors ; Stores all possible required number satisfying the given criteria ; Insert all element [ L , R ] ; Traverse the set ; Remove the multiples of ele ; Print the resultant numbers ; Driver Code
import java . util . * ; class GFG { static void elementsCoprimeWithArr ( int A [ ] , int N , int L , int R ) { HashSet < Integer > S = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int curr_ele = A [ i ] ; for ( int j = 1 ; j <= Math . sqrt ( curr_ele ) + 1 ; j ++ ) { if ( curr_ele % j == 0 ) { S . add ( j ) ; S . add ( curr_ele / j ) ; } } } HashSet < Integer > store = new HashSet < Integer > ( ) ; for ( int i = L ; i <= R ; i ++ ) store . add ( i ) ; S . remove ( 1 ) ; for ( int it : S ) { int ele = it ; int index = 1 ; while ( index * ele <= R ) { store . remove ( index * ele ) ; index ++ ; } } for ( int i : store ) { System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 } ; int L = 1 , R = 10 ; int N = arr . length ; elementsCoprimeWithArr ( arr , N , L , R ) ; } }
Maximize matrix sum by flipping the sign of any adjacent pairs | Java program for the above approach ; Function to find the maximum sum of matrix element after flipping the signs of adjacent matrix elements ; Initialize row and column ; Stores the sum of absolute matrix element ; Find the minimum absolute value in the matrix ; Store count of negatives ; Find the smallest absolute value in the matrix ; Increment the count of negative numbers ; Find the absolute sum ; If the count of negatives is even then print the sum ; Subtract minimum absolute element ; Driver Code
import java . util . * ; class GFG { static int maxSum ( int [ ] [ ] matrix ) { int r = matrix . length ; int c = matrix [ 0 ] . length ; int sum = 0 ; int mini = Integer . MAX_VALUE ; int count = 0 ; for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) { int k = matrix [ i ] [ j ] ; mini = Math . min ( mini , Math . abs ( k ) ) ; if ( k < 0 ) count ++ ; sum += Math . abs ( k ) ; } } if ( count % 2 == 0 ) { return sum ; } else { return ( sum - 2 * mini ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] matrix = { { 2 , - 2 } , { - 2 , 2 } } ; System . out . print ( maxSum ( matrix ) ) ; } }
Find the last positive element remaining after repeated subtractions of smallest positive element from all Array elements | JAVA program for the above approach ; Function to calculate last positive element of the array ; Return the first element if N = 1 ; Stores the greatest and the second greatest element ; Traverse the array A [ ] ; If current element is greater than the greatest element ; If current element is greater than second greatest element ; Return the final answer ; Driver Code
import java . util . * ; class GFG { static int lastPositiveElement ( int [ ] arr ) { int N = arr . length ; if ( N == 1 ) return arr [ 0 ] ; int greatest = - 1 , secondGreatest = - 1 ; for ( int x : arr ) { if ( x >= greatest ) { secondGreatest = greatest ; greatest = x ; } else if ( x >= secondGreatest ) { secondGreatest = x ; } } return greatest - secondGreatest ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 4 , 7 } ; System . out . print ( lastPositiveElement ( arr ) ) ; } }
Reduce given array by replacing subarrays with values less than K with their sum | Java program for the above approach ; Function to replace all the subarray having values < K with their sum ; Stores the sum of subarray having elements less than K ; Stores the updated array ; Traverse the array ; Update the sum ; Otherwise , update the vector ; Print the result ; Driver Code
import java . util . * ; class GFG { static void updateArray ( int [ ] arr , int K ) { int sum = 0 ; ArrayList < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] < K ) { sum += arr [ i ] ; } else { if ( sum != 0 ) { res . add ( sum ) ; } sum = 0 ; res . add ( arr [ i ] ) ; } } if ( sum != 0 ) res . add ( sum ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 200 , 6 , 36 , 612 , 121 , 66 , 63 , 39 , 668 , 108 } ; int K = 100 ; updateArray ( arr , K ) ; } }
Find if path length is even or odd between given Tree nodes for Q queries | Java program for the above approach ; Stores the input tree ; Stores the set number of all nodes ; Function to add an edge in the tree ; Function to convert the given tree into a bipartite graph using BFS ; Set the set number to - 1 for all node of the given tree ; Stores the current node during the BFS traversal of the tree ; Initialize the set number of 1 st node and enqueue it ; BFS traversal of the given tree ; Current node ; Traverse over all neighbours of the current node ; If the set is not assigned ; Assign set number to node u ; Function to find if the path length between node A and B is even or odd ; If the set number of both nodes is same , path length is odd else even ; Driver Code ; Function to convert tree into bipartite
import java . io . * ; import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] adj = new Vector [ 100000 ] ; static Vector < Integer > setNum = new Vector < Integer > ( 100000 ) ; static void addEdge ( int a1 , int a2 ) { adj [ a1 ] . add ( a2 ) ; adj [ a2 ] . add ( a1 ) ; } static void toBipartite ( int N ) { for ( int i = 0 ; i < 100000 ; i ++ ) setNum . add ( - 1 ) ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( 0 ) ; setNum . set ( 0 , 0 ) ; while ( ! q . isEmpty ( ) ) { int v = q . peek ( ) ; q . remove ( ) ; for ( int u : adj [ v ] ) { if ( setNum . get ( u ) == - 1 ) { setNum . set ( u , setNum . get ( v ) ^ 1 ) ; q . add ( u ) ; } } } } static void pathLengthQuery ( int A , int B ) { if ( setNum . get ( A ) == setNum . get ( B ) ) { System . out . println ( " Odd " ) ; } else { System . out . println ( " Even " ) ; } } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 100000 ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; int N = 7 ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 4 ) ; addEdge ( 3 , 5 ) ; addEdge ( 2 , 6 ) ; toBipartite ( N ) ; pathLengthQuery ( 4 , 2 ) ; pathLengthQuery ( 0 , 4 ) ; } }
Minimum size of set having either element in range [ 0 , X ] or an odd power of 2 with sum N | Java program for the above approach ; Function to find the highest odd power of 2 in the range [ 0 , N ] ; If P is even , subtract 1 ; Function to find the minimum operations to make N ; If N is odd and X = 0 , then no valid set exist ; Stores the minimum possible size of the valid set ; Loop to subtract highest odd power of 2 while X < N , step 2 ; If N > 0 , then increment the value of answer by 1 ; Return the resultant size of set ; Driver Code
import java . io . * ; class GFG { static int highestPowerof2 ( int n ) { int p = ( int ) Math . floor ( Math . log ( n ) / Math . log ( 2.0 ) ) ; if ( p % 2 == 0 ) p -= 1 ; int result = ( int ) ( Math . pow ( 2 , p ) ) ; return result ; } static int minStep ( int N , int X ) { if ( N % 2 != 0 && X == 0 ) return - 1 ; int size = 0 ; while ( X < N ) { N -= highestPowerof2 ( N ) ; size += 1 ; } if ( N != 0 ) size += 1 ; return size ; } public static void main ( String [ ] args ) { int N = 11 ; int X = 2 ; System . out . println ( minStep ( N , X ) ) ; } }
Check if all the digits of the given number are same | Java program for the above approach ; Function to check if all the digits in the number N is the same or not ; Find the last digit ; Find the current last digit ; Update the value of N ; If there exists any distinct digit , then return No ; Otherwise , return Yes ; Driver Code
import java . io . * ; class GFG { public static String checkSameDigits ( int N ) { int digit = N % 10 ; while ( N != 0 ) { int current_digit = N % 10 ; N = N / 10 ; if ( current_digit != digit ) { return " No " ; } } return " Yes " ; } public static void main ( String args [ ] ) throws IOException { int N = 222 ; System . out . println ( checkSameDigits ( N ) ) ; } }
Find number formed by K times alternatively reducing X and adding Y to 0 | Java program for the above approach ; Function to find the value obtained after alternatively reducing X and adding Y to 0 total K number of times ; Stores the final result after adding only Y to 0 ; Stores the final number after reducing only X from 0 ; Return the result obtained ; Driver Code
import java . util . * ; class GFG { static int positionAfterKJumps ( int X , int Y , int K ) { int addY = Y * ( K / 2 ) ; int reduceX = - 1 * X * ( K / 2 + K % 2 ) ; return addY + reduceX ; } public static void main ( String [ ] args ) { int X = 2 , Y = 5 , K = 3 ; System . out . print ( positionAfterKJumps ( X , Y , K ) ) ; } }
Maximize the largest number K such that bitwise and of K till N is 0 | Java program for the above approach ; Function to find maximum value of k which makes bitwise AND zero . ; Take k = N initially ; Start traversing from N - 1 till 0 ; Whenever we get AND as 0 we stop and return ; Driver Code
import java . io . * ; class GFG { static int findMaxK ( int N ) { int K = N ; for ( int i = N - 1 ; i >= 0 ; i -- ) { K &= i ; if ( K == 0 ) { return i ; } } return 0 ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( findMaxK ( N ) ) ; } }
Count of unordered pair of indices such that ratio of elements at these indices is same as ratio of indices | Java program of the above approach ; Function of find the count of unordered pairs ( i , j ) in the array such that arr [ j ] / arr [ i ] = j / i . ; Stores the count of valid pairs ; Iterating over all possible pairs ; Check if the pair is valid ; Return answer ; Driver Code ; Function Call
import java . util . * ; class GFG { static int countPairs ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ j ] % arr [ i ] == 0 ) && ( j + 1 ) % ( i + 1 ) == 0 && ( arr [ j ] / arr [ i ] == ( j + 1 ) / ( i + 1 ) ) ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , - 2 , 4 , 20 , 25 , - 6 } ; int n = arr . length ; System . out . print ( countPairs ( arr , n ) ) ; } }
Count of N | Java program for the above approach ; Function to find the count of odd and even integers having N bits and K set bits ; Find the count of even integers ; Find the count of odd integers ; Print the total count ; Driver Code
import java . io . * ; class GFG { static long factorial ( int n ) { long ans = 1 ; while ( n >= 1 ) { ans *= n ; n -- ; } return ans ; } static void Binary_Num ( int n , int k ) { long num_even , num_odd ; if ( n - k - 1 >= 0 && k - 1 >= 0 ) { num_even = factorial ( n - 2 ) / ( factorial ( k - 1 ) * factorial ( n - k - 1 ) ) ; } else { num_even = 0 ; } if ( k - 2 >= 0 ) { num_odd = factorial ( n - 2 ) / ( factorial ( k - 2 ) * factorial ( n - k ) ) ; } else { num_odd = 0 ; } System . out . println ( num_even + " ▁ " + num_odd ) ; } public static void main ( String [ ] args ) { int N = 9 , K = 6 ; Binary_Num ( N , K ) ; } }