本文主要是介绍CSU 1337 费马大定理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CSU 1337
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu
Description
费马大定理:当n>2时,不定方程an+bn=cn没有正整数解。比如a^3+b^3=c^3没有正整数解。为了活跃气氛,我们不妨来个搞笑版:把方程改成a^3+b^3=c3,这样就有解了,比如a=4, b=9, c=79时4^3+9^3=793。
输入两个整数x, y, 求满足x<=a,b,c<=y的整数解的个数
Input
输入最多包含10组数据。每组数据包含两个整数x, y(1<=x,y<=10^8)。
Output
对于每组数据,输出解的个数。
Sample Input
1 10 1 20 123 456789
Sample Output
Case 1: 0 Case 2: 2 Case 3: 16
费马定理内容:当整数 
时,关于 
的方程 
没有正整数解。
思路:x和y的范围都是10^8,当a,b 超过1000时,显然等式是不可能成立的。
所以只要在x-1000里枚举a,b的值即可。
#include <stdio.h>
int main()
{int x,y;int c=1;while(scanf("%d%d",&x,&y)>0){if(x>1000)printf("0\n");int cnt=0;for(int a=x;a<=1000;a++)for(int b=x;b<=1000;b++)if((a*a*a+b*b*b)%10==3&&(a*a*a+b*b*b)/10>=x&&(a*a*a+b*b*b)/10<=y)cnt++;printf("Case %d: %d\n",c++,cnt);}return 0;
}
这篇关于CSU 1337 费马大定理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!