zcmu---1670: 和费马开个玩笑

1670: 和费马开个玩笑

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 50  Solved: 37
[ Submit][ Status][ Web Board]

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 101 20123 456789

Sample Output

Case 1: 0Case 2: 2Case 3: 16

HINT

Source

水题,第一思路直接算,一看范围十的八次稳超时,然后我们发现x<=c<=y;所以(c*10+3)开三次根号小于一千所以只要1-1000就好,直接硬算
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{

    int n,m,q,x,y,t=1,k,flag,f,ans,sum;
    while(~scanf("%d %d",&x,&y))
    {
        ans=0;
        for(int i=x;i<=1000;i++){
            for(int j=x;j<=1000;j++){
                sum=i*i*i+j*j*j;
                if(sum%10!=3)continue;
                if(sum/10>=x&&sum/10<=y){
                    ans++;
                }
            }
        }
        printf("Case %d: %d\n",t++,ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qibage/article/details/77368311
今日推荐