codeparrot/xlcost-text-to-code huggingface dataset:
Largest Sum Contiguous Subarray | Java program to print largest contiguous array sum ; Driver program to test maxSubArraySum
import java . io . * ; class GFG { static int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = a [ 0 ] ; int curr_max = a [ 0 ] ; for ( int i = 1 ; i < size ; i ++ ) { curr_max = Math . max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = a . length ; int max_sum = maxSubArraySum ( a , n ) ; System . out . println ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ " + max_sum ) ; } }
Largest Sum Contiguous Subarray | Java program to print largest contiguous array sum ; Driver code
class GFG { static void maxSubArraySum ( int a [ ] , int size ) { int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here += a [ i ] ; if ( max_so_far < max_ending_here ) { max_so_far = max_ending_here ; start = s ; end = i ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; s = i + 1 ; } } System . out . println ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ " + max_so_far ) ; System . out . println ( " Starting ▁ index ▁ " + start ) ; System . out . println ( " Ending ▁ index ▁ " + end ) ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = a . length ; maxSubArraySum ( a , n ) ; } }
Find minimum number of currency notes and values that sum to given amount | Java program to accept an amount and count number of notes ; function to count and print currency notes ; count notes using Greedy approach ; Print notes ; driver function
import java . util . * ; import java . lang . * ; public class GfG { public static void countCurrency ( int amount ) { int [ ] notes = new int [ ] { 2000 , 500 , 200 , 100 , 50 , 20 , 10 , 5 , 1 } ; int [ ] noteCounter = new int [ 9 ] ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( amount >= notes [ i ] ) { noteCounter [ i ] = amount / notes [ i ] ; amount = amount - noteCounter [ i ] * notes [ i ] ; } } System . out . println ( " Currency ▁ Count ▁ - > " ) ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( noteCounter [ i ] != 0 ) { System . out . println ( notes [ i ] + " ▁ : ▁ " + noteCounter [ i ] ) ; } } } public static void main ( String argc [ ] ) { int amount = 868 ; countCurrency ( amount ) ; } }
Minimum sum by choosing minimum of pairs from array | Java program to minimize the cost of array minimization ; Returns minimum possible sum in array B [ ] ; Driver Code
import java . util . Arrays ; public class GFG { static int minSum ( int [ ] A , int n ) { int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ; return ( min_val * ( n - 1 ) ) ; } static public void main ( String [ ] args ) { int [ ] A = { 3 , 6 , 2 , 8 , 7 , 5 } ; int n = A . length ; System . out . println ( ( minSum ( A , n ) ) ) ; } }
Program for Next Fit algorithm in Memory Management | Java program for next fit memory management algorithm ; Function to allocate memory to blocks as per Next fit algorithm ; Stores block id of the block allocated to a process ; Initially no block is assigned to any process ; pick each process and find suitable blocks according to its size ad assign to it ; Do not start from beginning ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; mod m will help in traversing the blocks from starting block after we reach the end . ; Driver program
import java . util . Arrays ; public class GFG { static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) { int allocation [ ] = new int [ n ] , j = 0 ; Arrays . fill ( allocation , - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; while ( j < m ) { count ++ ; if ( blockSize [ j ] >= processSize [ i ] ) { allocation [ i ] = j ; blockSize [ j ] -= processSize [ i ] ; break ; } j = ( j + 1 ) % m ; } } System . out . print ( " Process No . Process Size Block no . "); for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( i + 1 + " TABSYMBOL TABSYMBOL " + processSize [ i ] + " TABSYMBOL TABSYMBOL " ) ; if ( allocation [ i ] != - 1 ) { System . out . print ( allocation [ i ] + 1 ) ; } else { System . out . print ( " Not ▁ Allocated " ) ; } System . out . println ( " " ) ; } } static public void main ( String [ ] args ) { int blockSize [ ] = { 5 , 10 , 20 } ; int processSize [ ] = { 10 , 20 , 5 } ; int m = blockSize . length ; int n = processSize . length ; NextFit ( blockSize , m , processSize , n ) ; } }
Maximum profit by buying and selling a share at most twice |  ; adding array ; 80 / 30 / / \ 25 / 15 / / \ / 2 10 / \ / 8 ; traversing through array from ( i + 1 ) th position
import java . io . * ; import java . util . * ; class GFG { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int price [ ] = { 2 , 30 , 15 , 10 , 8 , 25 , 80 } ; int profit = 0 ; for ( int i = 1 ; i < price . length ; i ++ ) { int sub = price [ i ] - price [ i - 1 ] ; if ( sub > 0 ) profit += sub ; } System . out . print ( " Maximum ▁ Profit = " + profit ) ; } }
Find if there is a pair in root to a leaf path with sum equals to root 's data | Java program to find if there is a pair in any root to leaf path with sum equals to root 's key. ; A binary tree node has data , pointer to left child and a pointer to right child ; utility that allocates a new node with the given data and null left and right pointers . ; Function to print root to leaf path which satisfies the condition ; Base condition ; Check if current node makes a pair with any of the existing elements in set . ; Insert current node in set ; If result returned by either left or right child is true , return true . ; Remove current node from hash table ; A wrapper over printPathUtil ( ) ; create an empty hash table ; Recursively check in left and right subtrees . ; Driver code
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node newnode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static boolean printPathUtil ( Node node , HashSet < Integer > s , int root_data ) { if ( node == null ) return false ; int rem = root_data - node . data ; if ( s . contains ( rem ) ) return true ; s . add ( node . data ) ; boolean res = printPathUtil ( node . left , s , root_data ) || printPathUtil ( node . right , s , root_data ) ; s . remove ( node . data ) ; return res ; } static boolean isPathSum ( Node root ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; return printPathUtil ( root . left , s , root . data ) || printPathUtil ( root . right , s , root . data ) ; } public static void main ( String [ ] args ) { Node root = newnode ( 8 ) ; root . left = newnode ( 5 ) ; root . right = newnode ( 4 ) ; root . left . left = newnode ( 9 ) ; root . left . right = newnode ( 7 ) ; root . left . right . left = newnode ( 1 ) ; root . left . right . right = newnode ( 12 ) ; root . left . right . right . right = newnode ( 2 ) ; root . right . right = newnode ( 11 ) ; root . right . right . left = newnode ( 3 ) ; System . out . print ( isPathSum ( root ) == true ? " Yes " : " No " ) ; } }
Program for Least Recently Used ( LRU ) Page Replacement algorithm | Java program for page replacement algorithms ; Driver method ; To represent set of current pages . We use an Arraylist ; Insert it into set if not present already which represents page fault ; Check if the set can hold equal pages ; Increment page faults ; Remove the indexes page ; insert the current page
import java . util . ArrayList ; public class LRU { public static void main ( String [ ] args ) { int capacity = 4 ; int arr [ ] = { 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 } ; ArrayList < Integer > s = new ArrayList < > ( capacity ) ; int count = 0 ; int page_faults = 0 ; for ( int i : arr ) { if ( ! s . contains ( i ) ) { if ( s . size ( ) == capacity ) { s . remove ( 0 ) ; s . add ( capacity - 1 , i ) ; } else s . add ( count , i ) ; page_faults ++ ; ++ count ; } else { s . remove ( ( Object ) i ) ; s . add ( s . size ( ) , i ) ; } } System . out . println ( page_faults ) ; } }
Find the subarray with least average | A Simple Java program to find minimum average subarray ; Prints beginning and ending indexes of subarray of size k with minimum average ; k must be smaller than or equal to n ; Initialize beginning index of result ; Compute sum of first subarray of size k ; Initialize minimum sum as current sum ; Traverse from ( k + 1 ) ' th ▁ element ▁ to ▁ n ' th element ; Add current item and remove first item of previous subarray ; Update result if needed ; Driver method to test the above function ; Subarray size
class Test { static int arr [ ] = new int [ ] { 3 , 7 , 90 , 20 , 10 , 50 , 40 } ; static void findMinAvgSubarray ( int n , int k ) { if ( n < k ) return ; int res_index = 0 ; int curr_sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) curr_sum += arr [ i ] ; int min_sum = curr_sum ; for ( int i = k ; i < n ; i ++ ) { curr_sum += arr [ i ] - arr [ i - k ] ; if ( curr_sum < min_sum ) { min_sum = curr_sum ; res_index = ( i - k + 1 ) ; } } System . out . println ( " Subarray ▁ between ▁ [ " + res_index + " , ▁ " + ( res_index + k - 1 ) + " ] ▁ has ▁ minimum ▁ average " ) ; } public static void main ( String [ ] args ) { int k = 3 ; findMinAvgSubarray ( arr . length , k ) ; } }
Find element using minimum segments in Seven Segment Display | Java program to find minimum number of segments required ; Precomputed values of segment used by digit 0 to 9. ; Return the number of segments used by x . ; Finding sum of the segment used by each digit of a number . ; Initialising the minimum segment and minimum number index . ; Finding and comparing segment used by each number arr [ i ] . ; If arr [ i ] used less segment then update minimum segment and minimum number . ; Driver program
import java . io . * ; class GFG { static int [ ] seg = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; static int computeSegment ( int x ) { if ( x == 0 ) return seg [ 0 ] ; int count = 0 ; while ( x > 0 ) { count += seg [ x % 10 ] ; x /= 10 ; } return count ; } static int elementMinSegment ( int [ ] arr , int n ) { int minseg = computeSegment ( arr [ 0 ] ) ; int minindex = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int temp = computeSegment ( arr [ i ] ) ; if ( temp < minseg ) { minseg = temp ; minindex = i ; } } return arr [ minindex ] ; } static public void main ( String [ ] args ) { int [ ] arr = { 489 , 206 , 745 , 123 , 756 } ; int n = arr . length ; System . out . println ( elementMinSegment ( arr , n ) ) ; } }
Find the Largest number with given number of digits and sum of digits | Java program to find the largest number that can be formed from given sum of digits and number of digits ; Function to print the largest possible number with digit sum ' s ' and ' m ' number of digits ; If sum of digits is 0 , then a number is possible only if number of digits is 1 ; Sum greater than the maximum possible sum ; Create an array to store digits of result ; Fill from most significant digit to least significant digit ; Fill 9 first to make the number largest ; If remaining sum becomes less than 9 , then fill the remaining sum ; driver program
class GFG { static void findLargest ( int m , int s ) { if ( s == 0 ) { System . out . print ( m == 1 ? " Largest ▁ number ▁ is ▁ 0" : " Not ▁ possible " ) ; return ; } if ( s > 9 * m ) { System . out . println ( " Not ▁ possible " ) ; return ; } int [ ] res = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { if ( s >= 9 ) { res [ i ] = 9 ; s -= 9 ; } else { res [ i ] = s ; s = 0 ; } } System . out . print ( " Largest ▁ number ▁ is ▁ " ) ; for ( int i = 0 ; i < m ; i ++ ) System . out . print ( res [ i ] ) ; } public static void main ( String [ ] args ) { int s = 9 , m = 2 ; findLargest ( m , s ) ; } }
Shortest Superstring Problem | Java program to find shortest superstring using Greedy Approximate Algorithm ; Utility function to calculate minimum of two numbers ; Function to calculate maximum overlap in two given strings ; max will store maximum overlap i . e maximum length of the matching prefix and suffix ; check suffix of str1 matches with prefix of str2 ; compare last i characters in str1 with first i characters in str2 ; Update max and str ; check prefix of str1 matches with suffix of str2 ; compare first i characters in str1 with last i characters in str2 ; pdate max and str ; Function to calculate smallest string that contains each string in the given set as substring . ; run len - 1 times to consider every pair ; To store maximum overlap ; To store array index of strings involved in maximum overlap ; to store resultant string after maximum overlap ; res will store maximum length of the matching prefix and suffix str is passed by reference and will store the resultant string after maximum overlap of arr [ i ] and arr [ j ] , if any . ; Check for maximum overlap ; Ignore last element in next cycle ; If no overlap , append arr [ len ] to arr [ 0 ] ; Copy resultant string to index l ; Copy string at last index to index r ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static String str ; static int min ( int a , int b ) { return ( a < b ) ? a : b ; } static int findOverlappingPair ( String str1 , String str2 ) { int max = Integer . MIN_VALUE ; int len1 = str1 . length ( ) ; int len2 = str2 . length ( ) ; for ( int i = 1 ; i <= min ( len1 , len2 ) ; i ++ ) { if ( str1 . substring ( len1 - i ) . compareTo ( str2 . substring ( 0 , i ) ) == 0 ) { if ( max < i ) { max = i ; str = str1 + str2 . substring ( i ) ; } } } for ( int i = 1 ; i <= min ( len1 , len2 ) ; i ++ ) { if ( str1 . substring ( 0 , i ) . compareTo ( str2 . substring ( len2 - i ) ) == 0 ) { if ( max < i ) { max = i ; str = str2 + str1 . substring ( i ) ; } } } return max ; } static String findShortestSuperstring ( String arr [ ] , int len ) { while ( len != 1 ) { int max = Integer . MIN_VALUE ; int l = 0 , r = 0 ; String resStr = " " ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { int res = findOverlappingPair ( arr [ i ] , arr [ j ] ) ; if ( max < res ) { max = res ; resStr = str ; l = i ; r = j ; } } } len -- ; if ( max == Integer . MIN_VALUE ) arr [ 0 ] += arr [ len ] ; else { arr [ l ] = resStr ; arr [ r ] = arr [ len ] ; } } return arr [ 0 ] ; } public static void main ( String [ ] args ) { String [ ] arr = { " catgc " , " ctaagt " , " gcta " , " ttca " , " atgcatc " } ; int len = arr . length ; System . out . println ( " The ▁ Shortest ▁ Superstring ▁ is ▁ " + findShortestSuperstring ( arr , len ) ) ; } }
Minimum number of jumps to reach end | Java program to find Minimum number of jumps to reach end ; Returns minimum number of jumps to reach arr [ h ] from arr [ l ] ; Base case : when source and destination are same ; When nothing is reachable from the given source ; Traverse through all the points reachable from arr [ l ] . Recursively get the minimum number of jumps needed to reach arr [ h ] from these reachable points . ; Driver code
import java . util . * ; import java . io . * ; class GFG { static int minJumps ( int arr [ ] , int l , int h ) { if ( h == l ) return 0 ; if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ; int min = Integer . MAX_VALUE ; for ( int i = l + 1 ; i <= h && i <= l + arr [ l ] ; i ++ ) { int jumps = minJumps ( arr , i , h ) ; if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ; } return min ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 } ; int n = arr . length ; System . out . print ( " Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach ▁ end ▁ is ▁ " + minJumps ( arr , 0 , n - 1 ) ) ; } }
Camel and Banana Puzzle | DP | Java program of the above approach ; Stores the overlapping state ; Recursive function to find the maximum number of bananas that can be transferred to A distance using memoization ; Base Case where count of bananas is less that the given distance ; Base Case where count of bananas is less that camel 's capacity ; Base Case where distance = 0 ; If the current state is already calculated ; Stores the maximum count of bananas ; Stores the number of trips to transfer B bananas using a camel of capacity C ; Loop to iterate over all the breakpoints in range [ 1 , A ] ; Recursive call over the remaining path ; Update the maxCount ; Memoize the current value ; Return answer ; Function to find the maximum number of bananas that can be transferred ; Initialize dp array with - 1 ; Function Call ; Driver Code
public class GFG { final static int dp [ ] [ ] = new int [ 1001 ] [ 3001 ] ; static int recBananaCnt ( int A , int B , int C ) { if ( B <= A ) { return 0 ; } if ( B <= C ) { return B - A ; } if ( A == 0 ) { return B ; } if ( dp [ A ] [ B ] != - 1 ) { return dp [ A ] [ B ] ; } int maxCount = Integer . MIN_VALUE ; int tripCount = B % C == 0 ? ( ( 2 * B ) / C ) - 1 : ( ( 2 * B ) / C ) + 1 ; for ( int i = 1 ; i <= A ; i ++ ) { int curCount = recBananaCnt ( A - i , B - tripCount * i , C ) ; if ( curCount > maxCount ) { maxCount = curCount ; dp [ A ] [ B ] = maxCount ; } } return maxCount ; } static int maxBananaCnt ( int A , int B , int C ) { for ( int i = 0 ; i < 1001 ; i ++ ) for ( int j = 0 ; j < 3001 ; j ++ ) dp [ i ] [ j ] = - 1 ; return recBananaCnt ( A , B , C ) ; } public static void main ( String [ ] args ) { int A = 1000 ; int B = 3000 ; int C = 1000 ; System . out . println ( maxBananaCnt ( A , B , C ) ) ; } }
Count of valid arrays of size P with elements in range [ 1 , N ] having duplicates at least M distance apart | Java program for the above approach ; Function to calculate the total number of arrays ; If the size of the array is P ; Check if all elements are used atlease once ; Check if this state is already calculated ; Initialize the result ; Use a number from the list of unused numbers ; There are ' unused ' number of favourable choices ; Use a number from already present number atlease M distance back ; There are ' used ▁ - ▁ M ' number of favourable choices ; Store the result ; Function to solve the problem ; Initialize DP table : dp [ i ] [ j ] [ j ] i : current position / index j : number of used elements k : number of unused elements ; Driver Code
import java . io . * ; class GFG { static int calculate ( int position , int used , int unused , int P , int M , int dp [ ] [ ] [ ] ) { if ( position == P ) { return unused == 0 ? 1 : 0 ; } if ( dp [ position ] [ used ] [ unused ] != - 1 ) return dp [ position ] [ used ] [ unused ] ; int result = 0 ; if ( unused > 0 ) { result += calculate ( position + 1 , used + 1 , unused - 1 , P , M , dp ) * unused ; } if ( used > M ) { result += calculate ( position + 1 , used , unused , P , M , dp ) * ( used - M ) ; } return dp [ position ] [ used ] [ unused ] = result ; } static int solve ( int N , int P , int M ) { int [ ] [ ] [ ] dp = new int [ 101 ] [ 101 ] [ 101 ] ; for ( int i = 0 ; i < 101 ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) for ( int k = 0 ; k < 101 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } return calculate ( 0 , 0 , N , P , M , dp ) ; } public static void main ( String [ ] args ) { int N = 2 , M = 0 , P = 3 ; System . out . println ( solve ( N , P , M ) ) ; } }
Minimum number of jumps to reach end | Java program to find Minimum number of jumps to reach end ; Returns Minimum number of jumps to reach end ; jumps [ 0 ] will hold the result ; Minimum number of jumps needed to reach last element from last elements itself is always 0 ; Start from the second element , move from right to left and construct the jumps [ ] array where jumps [ i ] represents minimum number of jumps needed to reach arr [ m - 1 ] from arr [ i ] ; If arr [ i ] is 0 then arr [ n - 1 ] can 't be reached from here ; If we can direcly reach to the end point from here then jumps [ i ] is 1 ; Otherwise , to find out the minimum number of jumps needed to reach arr [ n - 1 ] , check all the points reachable from here and jumps [ ] value for those points ; initialize min value ; following loop checks with all reachable points and takes the minimum ; Handle overflow ; or Integer . MAX_VALUE ; Driver Code
class GFG { static int minJumps ( int arr [ ] , int n ) { int [ ] jumps = new int [ n ] ; int min ; jumps [ n - 1 ] = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ; else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ; else { min = Integer . MAX_VALUE ; for ( int j = i + 1 ; j < n && j <= arr [ i ] + i ; j ++ ) { if ( min > jumps [ j ] ) min = jumps [ j ] ; } if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ; else jumps [ i ] = min ; } } return jumps [ 0 ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 6 , 1 , 0 , 9 } ; int size = arr . length ; System . out . println ( " Minimum ▁ number ▁ of " + " ▁ jumps ▁ to ▁ reach ▁ end ▁ is ▁ " + minJumps ( arr , size ) ) ; } }
Count N |  ; Stores the dp states ; Check if a number is a prime or not ; Function to generate all prime numbers that are less than or equal to n ; Base cases . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of as non - prime ; Function to find the count of N - digit numbers such that the sum of digits is a prime number ; If end of array is reached ; If the sum is equal to a prime number ; Otherwise ; If the dp - states are already computed ; If index = 1 , any digit from [ 1 - 9 ] can be placed . If N = 1 , 0 also can be placed . ; Otherwise , any digit from [ 0 - 9 ] can be placed . ; Return the answer . ; Driver Code ; Initializing dp array with - 1 ; Initializing prime array to true ; Find all primes less than or equal to 1000 , which is sufficient for N upto 100 ; Given Input ; Function call
import java . util . Arrays ; class GFG { public static int [ ] [ ] dp = new int [ 100 ] [ 1000 ] ; public static boolean [ ] prime = new boolean [ 1005 ] ; public static void SieveOfEratosthenes ( int n ) { prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } public static int countOfNumbers ( int index , int sum , int N ) { if ( index == N + 1 ) { if ( prime [ sum ] == true ) { return 1 ; } return 0 ; } int val = dp [ index ] [ sum ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( index == 1 ) { for ( int digit = ( N == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } else { for ( int digit = 0 ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } return val ; } public static void main ( String args [ ] ) { for ( int [ ] row : dp ) Arrays . fill ( row , - 1 ) ; Arrays . fill ( prime , true ) ; SieveOfEratosthenes ( 1000 ) ; int N = 6 ; System . out . println ( countOfNumbers ( 1 , 0 , N ) ) ; } }