1670: 和费马开个玩笑
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 51 Solved: 38
[Submit][Status][Web Board]
Description
费马大定理:当n>2时,不定方程a^n+b^n=c^n没有整数解。比如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
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 51 Solved: 38
[Submit][Status][Web Board]
Description
费马大定理:当n>2时,不定方程a^n+b^n=c^n没有整数解。比如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
解析:c<10^8,所以c3<10^9,所以,a^3和b^3<c3<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;
}