1041: [haoi2008] full point time limit: 10 sec memory limit: 162 MB
Submit: 2027 solved: 853
[Submit] [Status] Description
Returns the number of points in the circumference of a given circle (x ^ 2 + y ^ 2 = R ^ 2.
Input
R
Output
Number of points
Sample input4sample output4hint
N <= 2000 000
Source
This topic can be understood by the primitive stock groups (x, y, z), x ^ 2 + y ^ 2 = Z, and gcd (X, y) = gcd (x, z) = gcd (y, z) = 1 can be expressed
X = a ^ 2-B ^ 2
Y = 2 * a * B
Z = a ^ 2 + B ^ 2
This topic is known as Z, so we can first SQRT (n) n's factor Z, and then SQRT (z) won't a, just for statistics.
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<set>#include<map>#include<vector>#include<string>#include<queue>using namespace std;#ifdef WIN32#define LL "%I64d"#else#define LL "%lld"#endif#define MAXN 1100#define MAXV MAXN*2#define MAXE MAXV*2#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLtypedef long long qword;inline int nextInt(){ char ch; int x=0; bool flag=false; do ch=getchar(),flag=(ch==‘-‘)?true:flag; while(ch<‘0‘||ch>‘9‘); do x=x*10+ch-‘0‘; while (ch=getchar(),ch<=‘9‘ && ch>=‘0‘); return x*(flag?-1:1);}qword n,m,nn;qword gcd(qword x,qword y){ return (x%y==0)?y:gcd(y,x%y);}int count(qword n){ qword x,y; if (n==1) { // cout<<"0 "<<nn<<endl; return 4; } qword l=ceil(sqrt(n)); int ans=0; for (x=1;x<l;x++) { y=sqrt(n-x*x); if (x*x+y*y!=n)continue; if (x>=y)break; if (gcd(y*y-x*x,2*y*y)!=1)continue; // cout<<(y*y-x*x)*(nn/n)<<" "<<2*x*y*(nn/n)<<endl; // cout<<2*x*y*(nn/n)<<" "<<(y*y-x*x)*(nn/n)<<endl; ans+=1+(x&&y); } return ans*4;}int main(){ freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int i,j,k; int x,y,z; scanf(LL,&n); nn=n; qword ans=0; qword l=ceil(sqrt(n)); for (i=1;i<l;i++) { if (n%i==0) { ans+=count(i); ans+=count(n/i); } } if (l*l==n)ans+=count(l); printf(LL"\n",ans); return 0;}
Bzoj 1041: [haoi2008] the entire point primitive stock group on the circle