URAL 1349. Farm (费马大定理)
2015-03-09 20:43
375 查看
1349. Farm
Time limit: 1.0 secondMemory limit: 64 MB
Here is a farm. Here is a farmer that counts how many animal live in his farm: a camels, b sheep, c green cockroaches. Occurs that an +
bn = cn. n is given. You are to find all the rest.
Input
n (0 ≤ n ≤ 100)Output
Three different integers (a, b and c) such that an + bn =cn, 1 ≤ a, b, c ≤ 100. If there are several solutions you should output the one where a is minimal. If there are several solutions with the minimal a you should output the one with
minimal b, and so on. Output −1 if there is no solution.
Samples
input | output |
---|---|
0 | -1 |
1 | 1 2 3 |
解析:根据费马大定理,当n>=时,无解,故直接枚举即可。
AC代码:
#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; }
费马大定理,真好^_^
相关文章推荐
- Ural1349(费马大定理)
- ural 1349
- 【二进制 && bitset】URAL - 2108 Oleg and Little Ponies
- bzoj1814 Ural 1519 Formula 1(插头dp模板题)
- [C# Source Code]Terrarium Farm.
- [URAL1519] Formula 1 [插头dp入门]
- URAL 1026. Questions and answers
- E - Buttons URAL - 1023
- SharePoint-Server Farm Configuration Not Complete
- [USACO08DEC]Trick or Treat on the Farm
- 添加web front到farm中throw securityexception解决方法
- 【URAL1039】RAILWAY TICKETS火车票
- Ural 1029
- ural 1017 Staircases
- ural 1039 Anniversary Party
- ural1753_三分
- ural 1008. Image Encoding
- ural 1085. Meeting
- URAL1023
- URAL 1209 110100100010000……