朱利尔1124
Java版本:public static int countPoints(int rSquare) {
if(rSquare<=2000000000&&rSquare>=1) {
int x,y,temp,res,count = 0;
x=(int)Math.sqrt(rSquare);
y=(int)Math.sqrt(rSquare);
for(int i=0;i<=x;i++){
for (int j = 0; j <=y; j++){
if(i*i+j*j==rSquare) {
count++;
}
}
}
if(Math.sqrt(rSquare)==(long)Math.sqrt(rSquare)){
temp = count-2;
res =temp*4+4;
System.out.println("格点数为" + res);
return res;
}else{
res = count*4;
System.out.println("格点数为" + res);
return res;
}
}else {
System.out.println("请输入1~2000000000之间的数");
return -1;
}
}