結果

問題 No.1232 2^x = x
ユーザー Fu_LFu_L
提出日時 2021-01-04 23:36:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 199,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 11:10:16
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef modint998244353 mint;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
ll modinv(ll a,ll MOD) {
    ll b=MOD,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=MOD; 
    if(u<0) u+=MOD;
    return u;
}
ll modpow(ll a,ll n,ll MOD){
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}
ll extgcd(ll a,ll b,ll& x,ll& y){
    ll d=a;
    if(b!=0){
        d=extgcd(b,a%b,y,x);
        y-=((a/b)*x);
    }else{
        x=1;
        y=0;
    }
    return d;
}

ll t;
ll p;
ll b[100];
ll T;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>t;
    b[0]=1;
    rep(i,1,40){
        b[i]=b[i-1]*2;
    }
    while(t--){
        cin>>p;
        T=p-1;
        if(p==2){
            cout<<2<<endl;
        }else{
            rep(i,0,40){
                if(p==b[i]-1){
                    T=i;
                }
            }
            ll x,y;
            extgcd(T,p,x,y);
            if(x<0){
                x+=p;
            }
            //cout<<modpow(2,T*x,p)<<" "<<(T*x)%p<<endl;
            cout<<T*x<<endl;
        }
    }

}
0