Check if N leaves only distinct remainders on division by all values up to K | C # 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
using System ; using System . Collections . Generic ; class GFG { static bool 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 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }