Given N ( 2 < N < 1000 ) is a positive integer.
Jack had written a program to find k numbers a1,a2,a3,...ak, so as:
(a1+1) * ( a2+1 ) * .... * (ak+1) = n*a1*a2*...*ak Find the minimum k.
Example: INP: 4 OUT: 2
a1=a2=1, (1+1) * (1+1) = 2*2 = 4 = 4*a1*a2 = 4*1*1 = 4









From the expression:
(a1 + 1)(a2 + 1)..(ak + 1) = n * a1 * a2 * .. * ak
<=>
Consider
:
=>
So we will create a directed graph that vertex ith has value ni. Two vertexs ni and nj are adjacent if there is exist a positive integer am that
and
. Then minimum value of k is the shortest path between vertex value n and vertex value 1. We can you Breadth-first search to find the shortest path.
P/s: I remember that this is PTNK problem for grade 9 right?
Isn't it possible that A[i]+1 divides A[i+1] or something else?
Why is n * ai / (ai + 1) always an integer? Take n = 5, k = 3, a1 = a2 = 1, a3 = 4. then 5*(1/2) is not an integer...
:P May be I was wrong