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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool is_distinct ( long long n , long long k ) { unordered_set < long long > s ; for ( int i = 1 ; i <= k ; i ++ ) { long long tmp = n % i ; if ( s . find ( tmp ) != s . end ( ) ) { return false ; } s . insert ( tmp ) ; } return true ; } int main ( ) { long long N = 5 , K = 3 ; if ( is_distinct ( N , K ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }