Find Nth item distributed from infinite items of infinite types based on given conditions | Java Program for the above approach ; Function to find the type of the item given out according to the given rules ; Stores the count of item given out at each step ; Iterate over the days from 1 ; Iterate over type of item on that day ; Count of items given out should exceed n ; Driver Code
import java . io . * ; class GFG { static int itemType ( int n ) { int count = 0 ; for ( int day = 1 ; ; day ++ ) { for ( int type = day ; type > 0 ; type -- ) { count += type ; if ( count >= n ) return type ; } } } public static void main ( String [ ] args ) { int N = 10 ; System . out . println ( itemType ( N ) ) ; } }