CSU - 1337 (搞笑版费马大定理 )

时间:2023-03-09 09:55:06
CSU - 1337 (搞笑版费马大定理 )

费马大定理:当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

//感觉自己最这一类题做的神经有点错乱了,总以为会超时,然后就不敢做。。
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; typedef long long ll;
const int maxn=1100;
const int INF=0x3f3f3f3f; int main()
{
int x,y,ans;
int cas=1;
while(scanf("%d %d",&x,&y)!=EOF)
{
ans=0;
for(int a=x; a<=y; a++)
{
for(int b=x; b<=y; b++)
{
ll s=a*a*a+b*b*b;
if(s/10>y)break;
if(s%10==3)
{
if((s/10)>=x&&(s/10)<=y)
ans++;
}
}
if((a*a*a+x*x*x)/10>y)
break;
}
printf("Case %d: %d\n",cas++,ans);
}
}