Find the greatest gcd of the numbers \$n^m + k\$ and \$(n+1)^m + k\$ for given m
and k
.
For example, for m=3, k=1
we have:
- \$n = 1\$: \$\gcd(1^3 + 1, 2^3 + 1) = 1\$
- \$n = 2\$: \$\gcd(2^3 + 1, 3^3 + 1) = 1\$
\$\vdots\$
- \$n = 5\$: \$\gcd(5^3 + 1, 6^3 + 1) = 7\$ (max)
\$\vdots\$
- \$n \to \infty\$
Input/Output
Input is L lines through file or stdin, EOF terminated. Each line contains two integers: m
and k
separated by a space.
Output is L integers separated by any pattern of whitespace characters (tabs, spaces, newlines etc).
Examples
Input
2 4
2 7
3 1
4 1
3 2
5 4
10 5
Output
17
29
7
17
109
810001
3282561
Update
I can't find a proof that the solution is bounded for all n
given some m
and k
, so you only have to find the GGCD for \$n < 10,000,000\$.
n
is 810001? \$\endgroup\$