既然2019,X,Y的平方成等差序列,那么我们只要从用X=2020开始找第三个数,这个数Y用sqrt后取整得z,若z^2==Y,就是我们要找的。
代码如下所示:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// 请在此输入您的代码
int x=2019;
for(int y=2020;;++y)
{
int c=2*y*y-x*x;
int z=sqrt(c);
if(z*z==c)
{
cout<<z+y;
return 0;
}
}
// cout<<7020;
}