Check if N leaves only distinct remainders on division by all values up to K | Java program to check if all remainders are distinct or not ; Function to check and return if all remainders are distinct ; Stores the remainder ; Calculate the remainder ; If remainder already occurred ; Insert into the set ; Driver Code
import java . util . * ; class GFG { static boolean is_distinct ( long n , long k ) { HashSet < Long > s = new HashSet < Long > ( ) ; for ( int i = 1 ; i <= k ; i ++ ) { long tmp = n % i ; if ( s . contains ( tmp ) ) { return false ; } s . add ( tmp ) ; } return true ; } public static void main ( String [ ] args ) { long N = 5 , K = 3 ; if ( is_distinct ( N , K ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }