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

    歡迎訪問 生活随笔!

    生活随笔

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

    编程问答

    bzoj3884 上帝与集合的正确用法

    發布時間:2024/8/26 编程问答 34 豆豆
    生活随笔 收集整理的這篇文章主要介紹了 bzoj3884 上帝与集合的正确用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

    題意:求2^2^2^2^2.......^2%p的值,T組詢問。

    歐拉降冪多用幾次就好了。

    順便試了下fwrite輸出優化 ,效果顯著。

    #include<cstring> #include<iostream> #include<cctype> #include<cstdio> #define writ(x,c) write(x),push(c); using namespace std; inline char nc() {static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } inline int read() {char c;int x=0;bool f=0;for(; !isdigit(c); c=nc()) if(c=='-') f=1;for(; isdigit(c); c=nc()) x=(x<<1)+(x<<3)+c-48;return (f ? -x : x); } char pbuf[100000],*pp=pbuf; void push(const char c) {if(pp-pbuf==100000) fwrite(pbuf,1,100000,stdout),pp=pbuf;*pp++=c; } void write(int x) {static int sta[35];int top=0;do{sta[top++]=x%10,x/=10;}while(x);while(top) push(sta[--top]+'0'); } const int M=1001001; int phi[M],prime[M],tot; bool not_prime[M]; inline int Phi(int x) {int i,re=x;for(i=2; i*i<=x; i++)if(x%i==0){re/=i;re*=i-1;while(x%i==0)x/=i;}if(x^1) re/=x,re*=x-1;return re; } inline int KSM(long long x,int y,int p) {long long res=1;while(y){if(y&1) (res*=x)%=p;(x*=x)%=p;y>>=1;}return res%p; } inline int calc(int p) {if(p==1) return 0;int tmp=0,cur,res;while(~p&1) p>>=1,++tmp;cur=Phi(p);res=calc(cur);(res+=cur-tmp%cur)%=cur,res=KSM(2,res,p);return res<<tmp; } int main() {register int T=read(),p;while(T--){p=read();writ(calc(p),'\n');}fwrite(pbuf,1,pp-pbuf,stdout); }

    ?

    轉載于:https://www.cnblogs.com/mordor/p/9776495.html

    總結

    以上是生活随笔為你收集整理的bzoj3884 上帝与集合的正确用法的全部內容,希望文章能夠幫你解決所遇到的問題。

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