1349. Farm
time limit:1.0 second
Memory limit:64 MB
Here is a farm. Here is a farmer this counts how many animal live in his farm:a camels, B sheep, C green cockroaches. Occurs a n + b n = c N. N is given. You is to find all the rest. Input N (0≤n≤100) Output three different integers (a, B and C) such that a n + b n = c N, 1≤a, B, c≤100. If There is several solutions you should output, the one where a is minimal. If there is several solutions with the minimal a you should output of the one with minimal B, and so on. output−1 If there is no solution. Samples
input |
Output |
0
|
-1
|
1
|
1 2 3
|
Test instructions: Given n to find a, B and C to meet, a^n + b^n = c^n.
Analysis: According to Flt theorem, when n>=, there is no solution, so the direct enumeration can be.
AC Code:
#include <cstdio>
int main () {
int n;
while (scanf ("%d", &n) ==1) {
if (n = = 1) puts ("1 2 3");
else if (n = = 2) puts ("3 4 5");
Else puts ("1");
}
return 0;
}
Flt theorem, that's good ^_^