Given an integer N. The task is to find the number of divisors of all the numbers in the range [1, N].
Input: N = 5
Output: 1 2 2 3 2
divisors(1) = 1
divisors(2) = 1 and 2
divisors(3) = 1 and 3
divisors(4) = 1, 2 and 4
divisors(5) = 1 and 5
Input: N = 10
Output: 1 2 2 3 2 4 2 4 3 4
Approach: Create an array arr of the size (N + 1) where arr[i] stores the number of divisors of i. Now for every j from the range [1, N], increment all the elements which are divisible by j.
For example, if j = 3 then update arr, arr, arr, …
Below is the implementation of the above approach:
1 2 2 3 2 4 2 4 3 4
- Program to find count of numbers having odd number of divisors in given range
- Find numbers with n-divisors in a given range
- Find numbers with K odd divisors in a given range
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Sum of all prime divisors of all the numbers in range L-R
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Sum of product of proper divisors of all Numbers lying in range [L, R]
- Find sum of divisors of all the divisors of a natural number
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Querying maximum number of divisors that a number in a given range has
- Number of ways to obtain each numbers in range [1, b+c] by adding any two numbers in range [a, b] and [b, c]
- Count elements in the given range which have maximum number of divisors
- Find all divisors of first N natural numbers
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.