BZOJ 3884 上帝與集合的正確用法 歐拉定理,bzoj3884

來源:互聯網
上載者:User

BZOJ 3884 上帝與集合的正確用法 歐拉定理,bzoj3884

題目大意:求2^(2^(2^(2^(2^...)))) mod p的值

SB出題人被各種亂艸系列……

其實是某天腦洞比較大突然想算算這東西= = 然後就發現了這個好玩的性質= =

其實+∞個2看著嚇人其實沒啥可怕的= =


#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 10001000using namespace std;int phi[M],prime[1001001],tot;bool not_prime[M];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;}int Quick_Power(long long x,int y,int p){    long long re=1;    while(y)    {        if(y&1) (re*=x)%=p;        (x*=x)%=p; y>>=1;    }    return re;}int Solve(int p){    if(p==1) return 0;    int temp=0;    while(~p&1) p>>=1,++temp;    int phi_p=Phi(p);    int re=Solve(phi_p);    (re+=phi_p-temp%phi_p)%=phi_p;    re=Quick_Power(2,re,p)%p;    return re<<temp;}int main(){    int T,p;    for(cin>>T;T;T--)    {        scanf("%d",&p);        printf("%d\n",Solve(p));    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.