Count of distinct remainders when N is divided by all the numbers from the range [ 1 , N ] | Java implementation of the above approach ; Function to return the count of distinct remainders that can be obtained when n is divided by every element from the range [ 1 , n ] ; If n is even ; If n is odd ; Driver code
class GFG { static int distinctRemainders ( int n ) { if ( n % 2 == 0 ) return ( n / 2 ) ; return ( 1 + ( n / 2 ) ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( distinctRemainders ( n ) ) ; } }