Problem Statement: Given an integer $$$N > 1$$$, determine the expected number of divisions needed to reduce $$$N$$$ to 1 by repeatedly dividing it by one of its divisors (including $$$N$$$). Output the expected number of steps to reduce it to 1, accurate to at least 5 decimal places. Constraints: There will be $$$T$$$ test cases, where $$$1 < T < 10^4$$$ and $$$1 < N < 10^5$$$.
My Approach: Defining an array $$$\text{dp}$$$ such that $$$\text{dp}[N]$$$ represents the expected number of steps needed to reduce $$$N$$$ to 1. The base case is:
For each integer $$$N > 1$$$, we calculate $$$\text{dp}[N]$$$ using this:
where $$$k$$$ is the number of divisors of $$$N$$$ (excluding 1). The term $$$\text{dp}\left[\frac{N}{d}\right] + 1$$$ accounts for the expected steps needed after dividing $$$N$$$ by its divisor $$$d$$$ and includes the division step itself. Then, we iterate through all integers from $$$2$$$ to the maximum $$$N$$$ required, precomputing the values of $$$\text{dp}[N]$$$. This ensures that each test case can be answered in constant time $$$O(1)$$$ by simply returning $$$\text{dp}[N]$$$.
But implementing this approach is not giving AC & I can't find any drawbacks. Can someone help to identify any issue or any new approach? Thanks in advance for you time and effort.
you can use prime factorization
Could you provide a bit more detail?
use the sieve to prime factorize the number in O(logn) and the sum of the prime powers will be the ans
20 = 2^2 *5^1
2+1=3
1.20/2=10
2.10/2=5
3.5/5= 1
Got it. Thanks a bunch for your help.
Can I see your submission please?
Yeah, sure. The main part: