結果

問題 No.25 有限小数
ユーザー drymousedrymouse
提出日時 2024-02-17 23:15:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 68,800 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-17 23:15:07
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

long long long_gcd(long long a, long long b) {
    if (a < b) {
        long long x = a;
        a = b; b = x;
    }
    long long r;
    for (;b > 0;){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int last_dig(long long a) {
    if (a == 0) {return 0;}
    for (;a % 10 == 0;) {
        a /= 10;
    }
    return a % 10;
}

int main(void) {
    long long N, M;
    cin >> N >> M;
    long long daiyaku = long_gcd(N, M);
    long long nshou = N / daiyaku;
    long long mshou = M / daiyaku;
    if (mshou == 1) {
        cout << last_dig(nshou) << endl;
        return 0;
    }
    long long digit = nshou % mshou;
    for (;mshou % 2 == 0;) {
        digit *= 5;
        mshou /= 2;

    }
    digit = last_dig(digit);
    for (;mshou % 5 == 0;) {
        digit <<= 1;
        mshou /= 5;
    }
    if (mshou > 1) {
        cout << -1 << endl;
    } else {
        digit = last_dig(digit);
        cout << digit << endl;
    }

    return 0;
}
0