日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[SDOI2011] 计算器

發布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [SDOI2011] 计算器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:戳我

三合一??
第一問是。。快速冪。
第二問求逆元。最后乘上z即可。
第三問bsgs模板了。
bsgs不會?戳我

代碼如下:

#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<map> using namespace std; int t,k,y,z,p; map<int,int>M; inline int pow(int x,int y) {int cur_ans=1;while(y){if(y&1) cur_ans=(1ll*cur_ans*x)%p;x=(1ll*x*x)%p;y>>=1;}return cur_ans%p; } int main() {#ifndef ONLINE_JUDGEfreopen("ce.in","r",stdin);#endifscanf("%d%d",&t,&k);while(t--){scanf("%d%d%d",&y,&z,&p);if(k==1) printf("%d\n",pow(y,z));else if(k==2) {if(y%p==0) {printf("Orz, I cannot find x!\n");continue;}printf("%d\n",1ll*pow(y,p-2)*z%p);}else if(k==3){bool flag=false;if(y%p==0) {printf("Orz, I cannot find x!\n");continue;}y%=p,z%=p;if(z==1) {printf("0\n");continue;}int m=sqrt(p)+1;M.clear();for(int i=0,t=z;i<m;t=1ll*t*y%p,i++) M[t]=i;for(int i=1,tt=pow(y,m),t=tt;i<=m;i++,t=1ll*tt*t%p)if(M.count(t)){printf("%d\n",m*i-M[t]);flag=true;break;}if(flag==false)printf("Orz, I cannot find x!\n");}}return 0; }

轉載于:https://www.cnblogs.com/fengxunling/p/10339325.html

總結

以上是生活随笔為你收集整理的[SDOI2011] 计算器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。