Joking with Fermat's Last Theorem UVA

来源:互联网 发布:天刀淘宝刷白发多少钱 编辑:程序博客网 时间:2024/05/22 04:28

题目链接:点击打开链接

题意:在 x 和 y之间有多少对a ,b ,c 使a^3+b^3==c;

题解:

           尽管题中给出x ,y 的范围是1~10^8,但实际上优化一下,c+10+3的1/3次方就是x,y的上限,然后循环暴就行了;


#include<iostream>#include<algorithm>#include<cmath>#include<cstdio>#include<cstring>#include<iomanip>using namespace std;int main(){    int a,b;    int kase=0;    while(cin>>a>>b){        int num=0;        double k=pow(b*10+3,1.0/3);        for(int i=a;i<int(k)+1;i++){            for(int j=a;j<int(k)+1;j++){                int temp=i*i*i+j*j*j;                if(temp>b*10+3||temp<a) continue;                if(temp%10==3) num++;            }        }        cout<<"Case "<<++kase<<": "<<num<<endl;    }    return 0;}


原创粉丝点击