結果

問題 No.1339 循環小数
ユーザー merom686merom686
提出日時 2021-01-16 00:51:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 84,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 19:27:16
合計ジャッジ時間 2,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

ll powmod(ll n, ll k, int m) {
    ll r = 1, t = n % m;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % m;
        t = t * t % m;
    }
    return r;
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        while (n % 2 == 0) n /= 2;
        while (n % 5 == 0) n /= 5;

        int x = n, t = n;
        for (int i = 2; i * i <= t; i++) {
            if (t % i == 0) {
                do t /= i; while (t % i == 0);
                x = x / i * (i - 1);
            }
        }
        if (t > 1) x = x / t * (t - 1);

        int r = n;
        for (int i = 1; i * i <= x; i++) {
            if (x % i == 0) {
                int j = x / i;
                if (powmod(10, i, n) == 1) r = min(r, i);
                if (powmod(10, j, n) == 1) r = min(r, j);
            }
        }

        cout << r << '\n';
    }

    return 0;
}
0