使命召唤5 日本发售:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/08 15:57:55

public class freefall {
public static void main(String[] args) {
int i = 1;
while (true) {
if ((Math.sqrt(i + 100) == (int) Math.sqrt(i + 100))
&& (Math.sqrt(i + 268) == (int) Math.sqrt(i + 268))) {
System.out.println(i);
break;
} else {
i++;
}
}
}
}

21

#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;

int main()
{
double n,m,temp1,temp2;
int flag;
for(int i=1; i<10000; i++){
flag=1;
n=i+100;
m=i+168;
temp1=sqrt(n);
temp2=sqrt(m);
if((int)temp1*(int)temp1==n)
if((int)temp2*(int)temp2==m)
cout<<i<<endl;
}
system("PAUSE");
return 0;

}
运行后结果为156