题意:在 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;
}
本文发布于:2024-01-28 13:11:51,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064187177661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |