#define LOCAL
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
long n,i,t,count;
while(cin>>n)
{
count=0;
for(i=0;i<=sqrt(n);i++)
{
if(fmod(sqrt(n-i*i),1)==0) //用fmod()效率不高,建议换种判定方法
count++;
}
if(fmod(sqrt(n),1)==0) //数学不好,一个公式试了半天 。。。
count=4*count-4;
else
count=4*count;
cout<<count<<endl;
}
return 0;
}
hdu 3835 - R(N)
本文介绍了一个C++程序,用于计算小于等于给定数值的所有整数格点的数量。程序利用了数学方法和循环来找出所有符合条件的格点,并通过条件判断确保计算的准确性。此外,还提供了一种特殊情况下格点计数的调整方法。

被折叠的 条评论
为什么被折叠?



