Given an integer N. The task is to find the number of integers 1 < x < N, for which x and x + 1 have the same number of positive divisors.
Input: N = 3
Divisors(1) = 1
Divisors(2) = 1 and 2
Divisors(3) = 1 and 3
Only valid x is 2.
Input: N = 15
Approach: Find the number of divisors of all numbers below N and store them in an array. And count the number of integers x such that x and x + 1 have the same number of positive divisors by running a loop.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find the number of divisors of all numbers in the range [1, n]
- Program to find count of numbers having odd number of divisors in given range
- Querying maximum number of divisors that a number in a given range has
- Count number of integers less than or equal to N which has exactly 9 divisors
- 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 the largest good number in the divisors of given number N
- Count elements in the given range which have maximum number of divisors
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find the sum of the number of divisors
- Find number from its divisors
- Find all divisors of a natural number | Set 2
- Find all divisors of a natural number | Set 1
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.