# 【BZOJ1041】圆上的整点（数论）

## 题解

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
int n,ans=1;
int fpow(int a,int b,int MOD)
{
int s=1;
while(b){if(b&1)s=1ll*s*a%MOD;a=1ll*a*a%MOD;b>>=1;}
return s;
}
bool Miller_Rabin(int n)
{
if(n==2)return true;
for(int tim=10;tim;--tim)
{
int a=rand()%(n-2)+2,p=n-1;
if(fpow(a,p,n)!=1)return false;
while(!(p&1))
{
p>>=1;int nw=fpow(a,p,n);
if(1ll*nw*nw%n==1&&nw!=1&&nw!=n-1)return false;
}
}
return true;
}
vector<int> fac;
int Pollard_rho(int n,int c)
{
int i=0,k=2,x=rand()%(n-1)+1,y=x;
while(233)
{
++i;x=(1ll*x*x%n+c)%n;
int d=__gcd((y-x+n)%n,n);
if(d!=1&&d!=n)return d;
if(x==y)return n;
if(i==k)y=x,k<<=1;
}
}
void Fact(int n,int c)
{
if(n==1)return;
if(Miller_Rabin(n)){fac.push_back(n);return;}
int p=n;while(p>=n)p=Pollard_rho(p,c--);
Fact(p,c);Fact(n/p,c);
}
int main()
{
cin>>n;Fact(n,233);sort(fac.begin(),fac.end());
for(int i=0,l=fac.size(),pos;i<l;i=pos+1)
{
int cnt=1;
pos=i;while(pos<l-1&&fac[i]==fac[pos+1])++pos,++cnt;
if(fac[i]==2)continue;
if(fac[i]%4==1)ans=ans*(cnt*2+1);
}
printf("%d\n",ans*4);
return 0;
}


posted @ 2018-08-09 19:33  小蒟蒻yyb  阅读(485)  评论(0编辑  收藏