#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int X=1e6+7;
struct asd{
int next;
int num;
LL id;
}q[X];
int link[X];
int tol;
void init()
{
tol=1;
for(int i=0;i<X;i++)
link[i]=0;
}
void add(LL p, int x)
{
q[tol].id=p;
q[tol].num=1;
q[tol].next=link[x];
link[x]=tol++;
}
int Find(LL p,int x)
{
for(int i=link[x];i!=0;i=q[i].next)
{
if(p==q[i].id)
{
q[i].num++;
return q[i].num;
}
}
return 0;
}
int main()
{
int n,a,b;
while(~scanf("%d",&n)&&n)
{
scanf("%d%d",&a,&b);
init();
LL x=b%n;
int ans=0;
while(1)
{
int temp=Find(x,x%X);
if(temp==0) add(x,x%X);
else if(temp==2) ans++;
else if(temp==3) break;
x=(a*x%n*x%n+b+n)%n;
}
printf("%d\n",n-ans);
}
return 0;
}
HDU1488【分离链接法】
最新推荐文章于 2020-09-29 10:58:36 发布