【样例输出1】
2
1
2
【样例输出2】
2
1
0
标签:inpu getc 处理 测试 getch 数据 desc for printf
输入包含多组数据。
1 #include <bits/stdc++.h> 2 #define il inline 3 #define RG register 4 #define ll long long 5 6 using namespace std; 7 8 map <ll,ll> mp; 9 10 il ll gi(){ 11 RG ll x=0,q=1; RG char ch=getchar(); 12 while ((ch<‘0‘ || ch>‘9‘) && ch!=‘-‘) ch=getchar(); 13 if (ch==‘-‘) q=-1,ch=getchar(); 14 while (ch>=‘0‘ && ch<=‘9‘) x=x*10+ch-48,ch=getchar(); 15 return q*x; 16 } 17 18 il ll qpow(RG ll a,RG ll b,RG ll p){ 19 RG ll ans=1; 20 while (b){ 21 if (b&1) ans=ans*a%p; 22 a=a*a%p,b>>=1; 23 } 24 return ans; 25 } 26 27 il ll exgcd(RG ll a,RG ll b,RG ll &x,RG ll &y){ 28 if (!b){ x=1,y=0; return a; } 29 RG ll t=exgcd(b,a%b,y,x); y-=a/b*x; return t; 30 } 31 32 int main(){ 33 #ifndef ONLINE_JUDGE 34 freopen("calc.in","r",stdin); 35 freopen("calc.out","w",stdout); 36 #endif 37 RG ll T=gi(),k=gi(); 38 if (k==1){ 39 while (T--){ 40 RG ll a=gi(),b=gi(),p=gi(); 41 printf("%lld\n",qpow(a,b,p)); 42 } 43 } 44 if (k==2){ 45 while (T--){ 46 RG ll a=gi(),b=gi(),p=gi(),x,y; a%=p,b%=p; 47 RG ll t=exgcd(a,p,x,y); while (x<0) x+=p; 48 if (b%t) puts("Orz, I cannot find x!"); 49 else printf("%lld\n",x*(b/t)%p); 50 } 51 } 52 if (k==3){ 53 while (T--){ 54 RG ll a=gi(),b=gi(),p=gi(),m=ceil(sqrt(p)); 55 a%=p,b%=p; if (!a && !b){ puts("1"); continue; } 56 if (!a){ puts("Orz, I cannot find x!"); continue; } 57 mp.clear(); RG ll am=qpow(a,m,p),fg=0; 58 for (RG ll i=0,t=b;i<m;++i,t=t*a%p) mp[t]=i; 59 for (RG ll i=1,x=am;i*i<=p+1;++i,x=x*am%p) 60 if (mp.count(x)){ printf("%lld\n",i*m-mp[x]),fg=1; break; } 61 if (!fg) puts("Orz, I cannot find x!"); 62 } 63 } 64 return 0; 65 }
标签:inpu getc 处理 测试 getch 数据 desc for printf
原文地址:http://www.cnblogs.com/wfj2048/p/7523090.html