Find Nth number in a sequence which is not a multiple of a given number | Java program for the above approach ; Function to find Nth number not a multiple of A in range [ L , R ] ; Calculate the Nth no ; Check for the edge case ; Driver Code ; Input parameters ; Function Call
import java . io . * ; class GFG { static void countNo ( int A , int N , int L , int R ) { int ans = L - 1 + N + ( int ) Math . floor ( ( N - 1 ) / ( A - 1 ) ) ; if ( ans % A == 0 ) { ans = ans + 1 ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int A = 5 , N = 10 , L = 4 , R = 20 ; countNo ( A , N , L , R ) ; } }