結果

問題 No.1232 2^x = x
ユーザー leaf_1415leaf_1415
提出日時 2020-09-18 21:36:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 73,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 10:04:53
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint modpow(llint a, llint n, llint mod)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1, mod)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2, mod) % mod;
	}
}

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint p;
	for(int i = 0; i < n; i++){
		cin >> p;
		if(p == 2){
			cout << 2 << endl;
			continue;
		}
		llint x = modpow(p-1, p-2, p);
		cout << x * (p-1) << endl;
	}
	
	return 0;
}
0