- #1

muna580

What is the smallest integer x >2006, such that x^7 and x terminate in the same five digits.

The answer I get is 75800. But when I punch in 75800 in the calculator, for some reason, the last 5 digits for this number and 75800^7 are not equal. Why?

Code:

```
import java.lang.Math;
public class Number21
{
public static void main (String[] args)
{
int result = Solve21(2006);
System.out.println("Number21 is: " + result);
System.out.println("Number21 rised to 7th power is: " + Math.pow(result,7));
}
public static int Solve21(int x)
{
int ANSWER =0;
boolean found = false;
int n = x;
while (!found)
{
long npow = (long)Math.pow(n,7);
String nStr = String.valueOf(n);
String npowStr = String.valueOf(npow);
if (n <= 9999)
{
nStr = "0"+nStr;
}
int nStrLength = nStr.length();
int npowStrLength = npowStr.length();
String nStrSub = nStr.substring((nStrLength-5),(nStrLength-1));
String npowStrSub = npowStr.substring((npowStrLength-5),(npowStrLength-1));
if (nStrSub.equals(npowStrSub))
{
ANSWER = n;
found = true;
}
//System.out.println("Currently N is: " + n);
n++;
}
return ANSWER;
}
}
```