結果

問題 No.1232 2^x = x
ユーザー Fu_LFu_L
提出日時 2021-01-04 23:37:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 195,860 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-23 08:26:33
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 4 ms
6,940 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 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<<T*x<<endl;
        }
    }

}
0