1039: 搞笑版费马大定理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
Source
湖南省第九届程序设计竞赛
今天模了这题很久 也就是 很久很久
小调试了下,发现数据爆了
然后用了这样一个条件来限制
(i*i*i + j*j*j <= len)
不知道怎么想的,完全没明白数据爆了,意味着什么
以前一听到说 数据爆掉了,就什么把int类型换成longlong,尽量的去保住这些数据,不让它们爆掉。
其实这里还是有些不同的
这里数据爆掉了:限制条件(i*i*i + j*j*j <= len)根本没起到限制的作用
在这里数据爆掉了就一定是超过了最大值了,所以我们可以把它直接扔掉。(除非它的数据真的很狠,就卡在那爆与不爆之间)
最后吐槽下360- - 开着360,代码运行时间4秒以上,关掉360运行时间就低于1秒了。。。
#include<iostream> #include<cstdio> #include<math.h> using namespace std; int x,y,n,num,len,ming,j; long long bao1,bao2,mm,bao11,bao22; int check() { num = 0; len = y*10 +3; for(int i = x; i <= y; i++) { bao1 = i*i; if(i > bao1) break; bao11 = i*bao1; if(i > bao11) break; for(int j = i; j <= y; j++) { bao2 = j*j; if(j > bao2) break; bao22 = j*bao2; if(j > bao22) break; mm = bao11 + bao22; if(mm <= len && mm%10 == 3) {num++;} else if(mm > len )break; } } num *= 2; printf("Case %d: %d\n",n,num); return 0; } int first() { n=0; while(scanf("%d%d",&x,&y)!=EOF) { n++; check(); } return 0; } int main() { freopen("1027.txt","r",stdin); first(); return 0; }