結果
| 問題 | No.1232 2^x = x |
| コンテスト | |
| ユーザー |
Fu_L
|
| 提出日時 | 2021-01-04 23:37:43 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 959 bytes |
| 記録 | |
| コンパイル時間 | 1,905 ms |
| コンパイル使用メモリ | 194,428 KB |
| 最終ジャッジ日時 | 2025-01-17 09:42:23 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
#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;
}
}
}
Fu_L