标签:blog std include pre bsp can namespace map code
BZOJ3239
BSGS
#include <cstdio> #include <cmath> #include <map> #define LL long long using namespace std; LL p,b,n; map <int,int> mp; LL qpow(LL bas,int powe,LL mo){ LL ret=1; for (;powe;bas*=bas,bas%=mo){ if (powe&1) ret*=bas,ret%=mo; powe=powe>>1; } return(ret); } int main(){ while (scanf("%lld%lld%lld",&p,&b,&n)!=EOF){ mp.clear(); int bl=(int)sqrt(p);LL tb,bas; bas=tb=qpow(b,bl,p); for (int i=1;i<=bl;i++){ if (mp[bas]==0) mp[bas]=i*bl; bas*=tb;bas%=p; } tb=1; LL ans=1e9; for (LL i=0;i<=bl;i++){ if (tb==n) ans=min(ans,i); LL t=qpow(tb,p-2,p)*n%p; if (mp[t]) ans=min(ans,mp[t]+i); tb*=b;tb%=p; } if (ans!=1e9) printf("%lld\n",ans);else printf("no solution\n"); } }
标签:blog std include pre bsp can namespace map code
原文地址:http://www.cnblogs.com/zhujiangning/p/6261593.html