Find the Nth natural number which is not divisible by A | Java code to Find the Nth number which is not divisible by A from the series ; Find the quotient and the remainder when k is divided by n - 1 ; If the remainder is not 0 multiply n by q and subtract 1 if remainder is 0 then multiply n by q and add the remainder ; Print the answer ; Driver code
class GFG { static void findNum ( int n , int k ) { int q = k / ( n - 1 ) ; int r = k % ( n - 1 ) ; int a = 0 ; if ( r != 0 ) a = ( n * q ) + r ; else a = ( n * q ) - 1 ; System . out . println ( a ) ; } public static void main ( String [ ] args ) { int A = 4 ; int N = 6 ; findNum ( A , N ) ; } }