csuoj 1337: 搞笑版费马大定理

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337

1337: 搞笑版费马大定理

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 625  Solved: 301
[Submit][Status][Web Board]

Description

费马大定理:当n>2时,不定方程an+bn=cn没有正整数解。比如a3+b3=c3没有正整数解。为了活跃气氛,我们不妨来个搞笑版:把方程改成a3+b3=c3,这样就有解了,比如a=4, b=9, c=79时43+93=793。

输入两个整数x, y, 求满足x<=a,b,c<=y的整数解的个数。

Input

输入最多包含10组数据。每组数据包含两个整数x, y(1<=x,y<=108)。

Output

对于每组数据,输出解的个数。

Sample Input

1 10
1 20
123 456789

Sample Output

Case 1: 0
Case 2: 2
Case 3: 16

HINT 

分析:

因为C最大为10^8 , 所以 a , b 最大可以设置为1000 ,( a ^ 3 + b ^ 3 )   最后一位肯定是3 ,这个条件可以提速 , 另外其值 除以10 之后肯定是在x 和  y 范围内的,这个条件也可以提速。

AC代码:

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <string>
 6 #include <math.h>
 7 #include <stdlib.h>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <map>
12 #include <list>
13 #include <iomanip>
14 #include <vector>
15 #pragma comment(linker, "/STACK:1024000000,1024000000")
16 #pragma warning(disable:4786)
17 
18 using namespace std;
19 
20 const int INF = 0x3f3f3f3f;
21 const int MAX = 1000 + 10;
22 const double eps = 1e-8;
23 const double PI = acos(-1.0);
24 
25 int main()
26 {
27   int x , y , a , b , c , first = 1;
28   while(~scanf("%d%d",&x , &y))
29   {
30         int ans = 0;
31         for(a = x;a <= 1000 && a <= y;a ++)
32             for(b = x;b <= 1000 && b <= y;b ++)
33             {
34                 int s = a * a * a + b * b * b;
35                 if(s % 10 != 3)
36                     continue;
37                 c = s / 10;
38                 if(c >= x && c <= y)
39                     ans ++;
40             }
41          printf("Case %d: %d
", first ++, ans);
42   }
43   return 0;
44 }
View Code
原文地址:https://www.cnblogs.com/jeff-wgc/p/4456477.html