Find all the possible remainders when N is divided by all positive integers from 1 to N + 1 | C # implementation of the approach ; Function to find all the distinct remainders when n is divided by all the elements from the range [ 1 , n + 1 ] ; Set will be used to store the remainders in order to eliminate duplicates ; Find the remainders ; Print the contents of the set ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findRemainders ( long n ) { List < long > vc = new List < long > ( ) ; for ( long i = 1 ; i <= Math . Ceiling ( Math . Sqrt ( n ) ) ; i ++ ) vc . Add ( n / i ) ; for ( long i = ( long ) ( n / Math . Ceiling ( Math . Sqrt ( n ) ) - 1 ) ; i >= 0 ; i -- ) vc . Add ( i ) ; vc . Reverse ( ) ; foreach ( long it in vc ) Console . Write ( it + " ▁ " ) ; } public static void Main ( String [ ] args ) { long n = 5 ; findRemainders ( n ) ; } }