比赛 2022级数学专题练习赛2 评测结果 WWAWAWWAWAWWAWWAWAW
题目名称 计算器 最终得分 36
用户昵称 op_组撒头屯 运行时间 6.212 s
代码语言 C++ 内存使用 2.42 MiB
提交时间 2022-12-19 21:51:08
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll fst(ll x,ll y,ll mod){
  5. if (!y)return 1;
  6. if (y&1)return x*fst(x,y-1,mod)%mod;
  7. ll p=fst(x,y/2,mod);return p*p%mod;
  8. }
  9. int main(){
  10. freopen ("supercompute.in","r",stdin);
  11. freopen ("supercompute.out","w",stdout);
  12. int T,K;scanf("%d%d",&T,&K);
  13. while(T--){
  14. ll y,z,p;scanf("%lld%lld%lld",&y,&z,&p);
  15. y%=p;z%=p;
  16. if (K==1){
  17. printf("%lld\n",fst(y,z,p));
  18. }
  19. if (K==2){
  20. if (y%p==0){
  21. if (z==0)printf("0\n");
  22. else printf("Orz, I cannot find x!\n");
  23. continue;
  24. }
  25. printf("%lld\n",z*fst(y,p-2,p)%p);
  26. }
  27. if (K==3){
  28. if (z==1){
  29. printf("0\n");continue;
  30. }
  31. ll now=1;bool ok=0;
  32. for (int i=1;i<=5000000;i++){
  33. now=now*y%p;
  34. if (now==z){
  35. printf("%lld\n",i);ok=1;break;
  36. }
  37. }
  38. if (!ok)printf("Orz, I cannot find x!\n");
  39. }
  40. }
  41. }
  42.  
  43.  
  44.