Given two positive integers n
and t
. Find the smallest positive integer k
such that there exist k
positive integers a1
, a2
, …, ak
that satisfy the following equation:
(a1 + t)*(a2 + t)*...*(ak + t) = n*a1*a2*...*ak
If there is no such k, output -1
.
Constraints: 1 <= n, t <= 1000.
Examples:
>>> 4 1
<<< 2
>>> 43 1
<<< 7
>>> 47 1
<<< 8
>>> 167 1
<<< 10
>>> 172 1
<<< 9
>>> 283 1
<<< 11
>>> 299 1
<<< 10
>>> 395 1
<<< 11
>>> 571 1
<<< 12
>>> 947 1
<<< 14
>>> 997 1
<<< 13
>>> 1 1
<<< -1
>>> 5 2
<<< 2
This is a number theory programming problem that i could not solve, and no one that i asked could solve it either, I think it is NP-hard.
I tried making a table answers[1001][1001] but don’t even know how to set it up as it will take a long time
cnm9a is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.