結果
問題 | No.3028 No.9999 |
ユーザー |
![]() |
提出日時 | 2025-02-21 22:30:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 4,000 ms |
コード長 | 1,042 bytes |
コンパイル時間 | 2,480 ms |
コンパイル使用メモリ | 199,004 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-21 22:30:54 |
合計ジャッジ時間 | 2,990 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios::sync_with_stdio(false);std::cin.tie(nullptr);}int eular_phi(int n) {vector<int> primes;int x = n;for (int i = 2; i * i <= n; i++) {if (x % i == 0) {primes.push_back(i);while (x % i == 0) {x /= i;}}}if (x > 1) {primes.push_back(x);}int res = n;for (int p : primes) {res /= p;res *= (p - 1);}return res;}int pow_mod(long long a, int n, int mod) {long long res = 1;while (n) {if (n & 1) {res = (res * a) % mod;}a = (a * a) % mod;n >>= 1;}return res;}int main() {fast_io();int n;cin >> n;if (n == 1) {cout << 1 << endl;return 0;}int phi = eular_phi(n);vector<int> divisors;for (int i = 1; i * i <= phi; i++) {if (phi % i == 0) {divisors.push_back(i);if (i * i != phi) {divisors.push_back(phi / i);}}}sort(divisors.begin(), divisors.end());for (int d : divisors) {if (pow_mod(10, d, n) == 1) {cout << d << endl;return 0;}}}