Problem Description
Problem Analysis
Back then I was thinking:
“The data isn’t large,
so brute-force traversal should be fine…”
I was still thinking that just now, too.
But on closer inspection, my solution for this problem was wrong…
Namely this:
| |
According to ZZULI OJ it was WA.
The expected output should be -1, but I output 1 40 40.
In other words, the computation was wrong for the case n=10.
I thought it was a data range issue.
So I rewrote it:
| |
But I found it was still wrong for n=10.
Thinking about it carefully, computing 100 to the 10th power really does involve huge numbers.
Then I searched on Baidu.
It seems this problem involves Fermat’s Last Theorem…
Baidu Baike: Fermat’s Last Theorem (mathematical theorem) - Baidu Baike
It then states:
Fermat’s Last Theorem, also known as “Fermat’s Final Theorem,” was proposed by the French mathematician Fermat. It asserts that when the integer n >2, the equation x^n + y^n = z^n has no positive integer solutions for x, y, z. After it was proposed, it went through conjectures and debates by many people and more than three hundred years of history, and was finally proved in 1995 by the British mathematician Andrew Wiles.
So this problem should be: when
n==1||n==2, output the result
when n>2, it should always output -1
That is, the code should be written like this:
| |
After uploading, it got AC…
-.-
By the way, their school does this problem in November?
Sigh…
Looks like I really am still being outclassed…
Problem link: [ZZULI] [1753] Math Two!