# BZOJ 1041: [HAOI2008]圆上的整点【高斯素数】

## 1041: [HAOI2008]圆上的整点

Time Limit: 10 Sec Memory Limit: 162 MB

Description

Input

Output

Sample Input

4

Sample Output

4

HINT

$r={p}_{1}^{{a}_{1}}\ast {p}_{2}^{{a}_{2}}\ast {p}_{3}^{{a}_{3}}\ast ...\ast {p}_{k}^{{a}_{k}}$
${r}^{2}=\left({p}_{1}^{{a}_{1}}\ast {p}_{2}^{{a}_{2}}\ast {p}_{3}^{{a}_{3}}\ast ...\ast {p}_{k}^{{a}_{k}}{\right)}^{2}={p}_{1}^{2{a}_{1}}\ast {p}_{2}^{2{a}_{2}}\ast {p}_{3}^{2{a}_{3}}\ast ...\ast {p}_{k}^{2{a}_{k}}$

$X\left(n\right)=\left\{\begin{array}{l}1\left(nmod4==1\right)\\ -1\left(nmod4==3\right)\\ 0\left(nmod2==0\right)\end{array}$

#include<cmath>
#include<cstdio>
#define LL long long
using namespace std;
LL n,m,Ans=1,p[500005];
bool vis[500005];
void make_p(){
int Len=500000;
vis[0]=vis[1]=1;
for(int i=2;i<=Len;i++){
if(!vis[i]) p[++p[0]]=i;
for(int j=1;j<=p[0]&&i*p[j]<=Len;j++){
vis[i*p[j]]=1;
if(!(i%p[j])) break;
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("prob.in","r",stdin);
freopen("prob.out","w",stdout);
#endif
make_p();
scanf("%lld",&n);
while(!(n&1)) n/=2;
for(int i=1;i<=p[0]&&p[i]<=n;i++)
if(!(n%p[i])){
LL Num=0;
while(!(n%p[i])) Num++,n/=p[i];
Num<<=1;
if(p[i]%4==1) Ans*=Num+1;
}
if(n>1) if(n%4==1) Ans*=3;
printf("%lld\n",Ans*4);
return 0;
}
posted @ 2018-05-03 16:14  XSamsara  阅读(38)  评论(0编辑  收藏