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
解析:C<10^8,所以C*10<10^9,所以a,b<10^3,开始遍历
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long x,y,casee=0;
while(~scanf("%lld %lld",&x,&y))
{
casee++;
long long i,j,cc=0;
for(i=x;i<=y&&i<1010;i++)
{
for(j=x;j<=y&&j<1010;j++)
{
long long ans=i*i*i+j*j*j;
long long kk=ans%10;
long long kkk=ans/10;
if(ans>=10&&kk==3&&kkk<=y)
cc++;
}
}
printf("Case %lld: %lld\n",casee,cc);
}
return 0;
}