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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count elements in the given range which have maximum number of divisors
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count the numbers < N which have equal number of divisors as K
- Count of integers up to N which are non divisors and non coprime with N
- Count number of integers less than or equal to N which has exactly 9 divisors
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Find sum of divisors of all the divisors of a natural number
- Count of numbers in range which are divisible by M and have digit D at odd places
- Check if a number has an odd count of odd divisors and even count of even divisors
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Count divisors of n that have at-least one digit common with n
- Divisors of n-square that are not divisors of n
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Check if count of even divisors of N is equal to count of odd divisors
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits
- Count integers in a range which are divisible by their euler totient value
- Find k numbers which are powers of 2 and have sum N | Set 1
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
- Generate a pair of integers from a range [L, R] whose LCM also lies within the range
- Program to find count of numbers having odd number of divisors in given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.