比赛 |
2022级数学专题练习赛2 |
评测结果 |
WWAWAWWAWAWWAWWAWAW |
题目名称 |
计算器 |
最终得分 |
36 |
用户昵称 |
op_组撒头屯 |
运行时间 |
6.212 s |
代码语言 |
C++ |
内存使用 |
2.42 MiB |
提交时间 |
2022-12-19 21:51:08 |
显示代码纯文本
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- ll fst(ll x,ll y,ll mod){
- if (!y)return 1;
- if (y&1)return x*fst(x,y-1,mod)%mod;
- ll p=fst(x,y/2,mod);return p*p%mod;
- }
- int main(){
- freopen ("supercompute.in","r",stdin);
- freopen ("supercompute.out","w",stdout);
- int T,K;scanf("%d%d",&T,&K);
- while(T--){
- ll y,z,p;scanf("%lld%lld%lld",&y,&z,&p);
- y%=p;z%=p;
- if (K==1){
- printf("%lld\n",fst(y,z,p));
- }
- if (K==2){
- if (y%p==0){
- if (z==0)printf("0\n");
- else printf("Orz, I cannot find x!\n");
- continue;
- }
- printf("%lld\n",z*fst(y,p-2,p)%p);
- }
- if (K==3){
- if (z==1){
- printf("0\n");continue;
- }
- ll now=1;bool ok=0;
- for (int i=1;i<=5000000;i++){
- now=now*y%p;
- if (now==z){
- printf("%lld\n",i);ok=1;break;
- }
- }
- if (!ok)printf("Orz, I cannot find x!\n");
- }
- }
- }
-
-
-