Given a positive integer N. The task is to find the number of divisor (say d) which give quotient (say q) on integer division (i.e q = N/d) such that quotient have less or equal set bit than divisor. In other words, find number of possible value of ‘d’ which will produce ‘q’ on integer dividing ‘n’ (q = N/d) such that ‘q’ have less or equal set bits (atleast 1) than ‘d’.
Input : N = 5 Output : 4 for d = 1 (set bit = 1), q = 5/1 = 5 (set bit = 2), count = 0. for d = 2 (set bit = 1), q = 5/2 = 2 (set bit = 1), count = 1. for d = 3 (set bit = 2), q = 5/3 = 1 (set bit = 1), count = 2. for d = 4 (set bit = 1), q = 5/4 = 1 (set bit = 1), count = 3. for d = 5 (set bit = 2), q = 5/5 = 1 (set bit = 1), count = 4. Input : N = 3 Output : 2
Observe, for all d > n, q have 0 set bit so there is no point to go above n.
Also, for n/2 < d <= n, it will return q = 1, which have 1 set bit which will always be less
than or equal to d. And, minimum possible value of d is 1. So, possible value of d is from 1 to n.
Now, observe on dividing n by d, where 1 <= d <= n, it will give q in sorted order (decreasing).
So, with increasing d we will get decreasing q. So, we get the two sorted sequence, one for increasing d
and other for decreasing q. Now, observe initially the number of set bit of d is greater than q but after
a point number of set bit of d is less than or equal to q.
So, our problem reduce to find that point i.e. ‘x’ for the value of d, from 1 <= d <= n, such that q have less than or equal set bit to d.
So, count of possible d such that q have less than or equal set bit to d will be equal to n – x + 1.
Below is the implementation of this approach :
- Quotient and remainder dividing by 2^k (a power of 2)
- Check if bits of a number has count of consecutive set bits in increasing order
- Count subarrays such that remainder after dividing sum of elements by K gives count of elements
- Count Divisors of n in O(n^1/3)
- Check if count of divisors is even or odd
- Count Divisors of Factorial
- Count divisors of n that have at-least one digit common with n
- Count divisors of array multiplication
- C Program to Check if count of divisors is even or odd
- Count all perfect divisors of a number
- Count of numbers below N whose sum of prime divisors is K
- Count total divisors of A or B in a given range
- Count the numbers < N which have equal number of divisors as K
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Java Program to Check if count of divisors is even or odd
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.