本文共 1571 字,大约阅读时间需要 5 分钟。
关于exbsgs是个什么东东可以去看看yyb大佬的博客->
1 //minamoto 2 #include 3 #include 4 #include 5 #include 6 #define ll long long 7 #define GG {puts("No Solution");} 8 using namespace std; 9 #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)10 char buf[1<<21],*p1=buf,*p2=buf;11 inline ll read(){12 #define num ch-'0'13 char ch;bool flag=0;ll res;14 while(!isdigit(ch=getc()))15 (ch=='-')&&(flag=true);16 for(res=num;isdigit(ch=getc());res=res*10+num);17 (flag)&&(res=-res);18 #undef num19 return res;20 }21 map mp;22 inline ll gcd(ll a,ll b){23 if(!b) return a;24 while(b^=a^=b^=a%=b);25 return a;26 }27 inline ll ksm(ll a,ll b,ll p){28 ll res=1;29 while(b){30 if(b&1) (res*=a)%=p;31 (a*=a)%=p,b>>=1;32 }33 return res;34 }35 inline void ex_BSGS(ll y,ll z,ll p){36 if(z==1) return (void)(puts("0"));37 int k=0,a=1;38 while(true){39 int d=gcd(y,p);if(d==1) break;40 if(z%d) return (void)(GG);41 z/=d,p/=d,++k,a=1ll*a*y/d%p;42 if(z==a) return (void)(printf("%d\n",k));43 }44 mp.clear();45 int m=sqrt(p)+1;46 for(int i=0,t=z;i =0&&i*m-j+k>=0) return (void)(printf("%d\n",i*m-j+k));50 }51 GG;52 }53 int main(){54 // freopen("testdata.in","r",stdin);55 while(true){56 int x=read(),z=read(),k=read();57 if(x==0&&z==0&&k==0) break;58 ex_BSGS(x,k,z);59 }60 return 0;61 }
转载于:https://www.cnblogs.com/bztMinamoto/p/9740806.html