Find n | Java program to find the value at n - th place in the given sequence ; Returns n - th number in sequence 1 , 1 , 2 , 1 , 2 , 3 , 1 , 2 , 4 , ... ; One by one subtract counts elements in different blocks ; Driver Code
import java . io . * ; class GFG { static int findNumber ( int n ) { n -- ; int i = 1 ; while ( n >= 0 ) { n -= i ; ++ i ; } return ( n + i ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( findNumber ( n ) ) ; } }