Given an integer N, the task is to find the count of total distinct remainders which can be obtained when N is divided by every element from the range [1, N].
Input: N = 5
5 % 1 = 0
5 % 2 = 1
5 % 3 = 2
5 % 4 = 1
5 % 5 = 0
The distinct remainders are 0, 1 and 2.
Input: N = 44
Approach: It can be easily observed that for even values of N the number of distinct remainders will be N / 2 and for odd values of N it will be 1 + ⌊N / 2⌋.
Below is the implementation of the above approach:
Time Complexity: O(1)
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Count of N-digit numbers with all distinct digits
- Count Odd and Even numbers in a range from L to R
- Count of numbers having only 1 set bit in the range [0, n]
- Count factorial numbers in a given range
- Count of numbers from range [L, R] whose sum of digits is Y
- Count the numbers divisible by 'M' in a given range
- Count numbers in range 1 to N which are divisible by X but not by Y
- Count of numbers from range [L, R] that end with any of the given digits
- Count of numbers from the range [L, R] which contains at least one digit that divides K
- Count numbers with unit digit k in given range
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Numbers in range [L, R] such that the count of their divisors is both even and prime
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.