結果
| 問題 |
No.1255 ハイレーツ・オブ・ボリビアン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-10 02:14:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 97 ms / 2,000 ms |
| コード長 | 1,659 bytes |
| コンパイル時間 | 1,605 ms |
| コンパイル使用メモリ | 172,916 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-23 08:48:01 |
| 合計ジャッジ時間 | 2,543 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char newl = '\n';
template<typename T>
map<T, int> prime_factor(T n) {
map<T, int> res;
for (T i = 2; i * i <= n; i++) {
while (n % i == 0) {
++res[i];
n /= i;
}
}
if (n != 1) res[n] = 1;
return res;
}
ll phi(ll n) {
ll res = 1;
for (ll i = 2; i * i <= n; i++) {
ll foo = 1, bar = 1;
while (n % i == 0) {
if (foo > 1) bar *= i;
foo *= i;
n /= i;
}
if (foo > bar) res *= foo - bar;
}
if (n != 1) res *= n - 1;
return res;
}
template<typename T>
vector<T> divisor(T n) {
vector<T> res;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.emplace_back(i);
if (i != n / i) res.emplace_back(n / i);
}
}
return res;
}
const ll MOD = 1000000007;
ll modpow(ll x, ll n, ll mod = MOD) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t;
cin >> t;
for (int i = 0; i < t; i++) {
ll n;
cin >> n;
if (n == 1) {
cout << 1 << newl;
continue;
}
vector<ll> d = divisor(phi(2 * n - 1));
sort(d.begin(), d.end());
ll ans = -1;
for (ll x : d) {
if (modpow(2, x, 2 * n - 1) == 1) {
ans = x;
break;
}
}
cout << ans << newl;
}
return 0;
}