結果

問題 No.1232 2^x = x
ユーザー KKT89KKT89
提出日時 2020-09-18 22:23:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 388 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 197,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 11:05:35
合計ジャッジ時間 2,850 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll mod_inv(ll a,ll p){
	ll b=p,x=1LL,y=0LL;
	while(b){
		ll t=a/b;
		a-=t*b; swap(a,b);
		x-=t*y; swap(x,y);
	}
	return (x%p+p)%p;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	while(n--){
		ll p; cin >> p;
		if(p!=2)printf("%lld\n",mod_inv(p-1,p)*(p-1));
		else printf("2\n");
	}
}
0