結果

問題 No.25 有限小数
ユーザー H3PO4H3PO4
提出日時 2023-02-20 10:48:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 841 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 88,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 09:59:48
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <unordered_map>

long long solve(long long N, long long M) {
    long long g = std::gcd(M, N);
    N /= g;
    M /= g;
    N %= 10;

    std::unordered_map<int, int> ct = {{2, 0},
                                       {5, 0}};
    for (const auto &x: {2, 5}) {
        while (M % x == 0) {
            ct.at(x)++;
            M /= x;
        }
    }
    if (M != 1) { return -1; }

    if (ct.at(2) <= ct.at(5)) {
        for (int i = 0; i < ct.at(5) - ct.at(2); i++) {
            N *= 2;
            N %= 10;
        }
    } else {
        for (int i = 0; i < ct.at(2) - ct.at(5); i++) {
            N *= 5;
            N %= 10;
        }
    }
    N %= 10;
    return N;
}

int main() {
    long long N, M;
    std::cin >> N;
    std::cin >> M;
    std::cout << solve(N, M) << std::endl;
}
0