結果

問題 No.1339 循環小数
ユーザー snrnsidysnrnsidy
提出日時 2021-08-07 15:53:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,028 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 208,556 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 23:32:32
合計ジャッジ時間 8,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;

map <int, int> res;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, t;

    cin >> t;

    while (t--)
    {
        cin >> n;
        while (1)
        {
            if (n % 2 != 0) break;
            n /= 2;
        }
        while (1)
        {
            if (n % 5 != 0) break;
            n /= 5;
        }

        if (n == 1)
        {
            cout << 1 << '\n';
        }
        else
        {
            if (res.find(n) == res.end())
            {
                int val = 1;
                for (int i = 1; ; i++)
                {
                    val *= 10;
                    val %= n;
                    if (val == 1)
                    {
                        res[n] = i;
                        break;
                    }
                }
                cout << res[n] << '\n';
            }
            else
            {
                cout << res[n] << '\n';
            }
        }
    }
    return 0;
}
0