結果
問題 | No.1339 循環小数 |
ユーザー |
![]() |
提出日時 | 2021-01-15 21:55:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 1,543 ms |
コンパイル使用メモリ | 169,516 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-26 14:25:08 |
合計ジャッジ時間 | 3,155 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long MOD){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long euler_phi(long long x){ long long ans = x; for (long long i = 2; i * i <= x; i++){ if (x % i == 0){ ans /= i; ans *= i - 1; while (x % i == 0){ x /= i; } } } if (x > 1){ ans /= x; ans *= x - 1; } return ans; } int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ int N; cin >> N; while (N % 2 == 0){ N /= 2; } while (N % 5 == 0){ N /= 5; } int p = euler_phi(N); vector<int> f; for (int j = 1; j * j <= p; j++){ if (p % j == 0){ f.push_back(j); if (j * j < p){ f.push_back(p / j); } } } int ans = N; for (int x : f){ if (modpow(10, x, N) == 1){ ans = min(ans, x); } } cout << ans << endl; } }