Given an integer N, the task is to find the value of F(N) if:
- F(1) = 0
- F(2) = 2
- F(N) = 0, if N is odd prime.
- F(N) = F(a) + F(b), where a and b are factors of N and (a + b) is minimum among all factors. Also a * b = N
Input: N = 5
Since 5 is an odd prime.
Input: N = 4
4 can be written as 2 * 2, hence f(2) + f(2) = 4
Input: N = 20
20 can be written as f(4) + f(5), and f(4) can be written as f(2) + f(2), which is 4.
Approach: The following steps can be followed to solve the problem:
- If N is 1 or 2, the answer is 0 or 2 respectively.
- On breaking the recurrence f(n) = f(a) + f(b), we get it is the number of times a number is divisible by 2.
- The answer for f(n) is 2 * (number of times a number if divisible by 2)
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.
- Find minimum x such that (x % k) * (x / k) == n | Set-2
- Find minimum x such that (x % k) * (x / k) == n
- Find the minimum value of X for an expression
- Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given
- Find two numbers with the given LCM and minimum possible difference
- Find minimum GCD of all pairs in an array
- Find the subarray of size K with minimum XOR
- Find the minimum permutation of A greater than B
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Find minimum sum of factors of number
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Find minimum possible digit sum after adding a number d
- Find the minimum number possible by changing at most one digit
- Find the minimum value of the given expression over all pairs of the array
- Find minimum speed to finish all Jobs
- Find the minimum number of steps to reach M from N
- Find the minimum possible health of the winning player
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Find the minimum cost to cross the River
- Find minimum number of coins that make a given value
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.