Check if N leaves only distinct remainders on division by all values up to K | Function to check and return if all remainders are distinct ; Stores the remainder ; Calculate the remainder ; If remainder already occurred ; Insert leto the set ; Driver code
function is_distinct ( n , k ) { let s = new Set ( ) ; for ( let i = 1 ; i <= k ; i ++ ) { let tmp = n % i ; if ( s . has ( tmp ) ) { return false ; } s . add ( tmp ) ; } return true ; } let N = 5 , K = 3 ; if ( is_distinct ( N , K ) ) document . write ( " " ) ; else document . write ( " " ) ;