結果

問題 No.1339 循環小数
ユーザー lorent_kyoprolorent_kyopro
提出日時 2021-01-15 23:45:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 198,848 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 19:13:37
合計ジャッジ時間 4,019 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 30 ms
4,380 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 32 ms
4,380 KB
testcase_24 AC 29 ms
4,380 KB
testcase_25 AC 33 ms
4,376 KB
testcase_26 AC 34 ms
4,380 KB
testcase_27 AC 33 ms
4,376 KB
testcase_28 AC 33 ms
4,376 KB
testcase_29 AC 28 ms
4,376 KB
testcase_30 AC 30 ms
4,380 KB
testcase_31 AC 70 ms
4,376 KB
testcase_32 AC 72 ms
4,376 KB
testcase_33 AC 33 ms
4,380 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 65 ms
4,376 KB
testcase_36 AC 32 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long euler_phi(long long n) {
    long long res = n;
    for (long long i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            res = res / i * (i - 1);
            while (n % i == 0) n /= i;
        }
    }
    if (n != 1) res = res / n * (n - 1);
    return res;
}

long long pow_mod(long long a, long long n, long long m) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    while (n % 2 == 0) n /= 2;
    while (n % 5 == 0) n /= 5;
    if (n == 1) {
        cout << 1 << '\n';
        return;
    }
    int phi = euler_phi(n);
    int ans = INT_MAX;
    for (long long i = 1; i * i <= phi; ++i) {
        if (phi % i == 0) {
            if (pow_mod(10, i, n) == 1) ans = min<int>(ans, i);
            if (pow_mod(10, phi / i, n) == 1) ans = min<int>(ans, phi / i);
        }
    }
    cout << ans << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}
0