結果

問題 No.25 有限小数
ユーザー maine_honzuki
提出日時 2020-05-05 21:08:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 167,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-27 04:08:42
合計ジャッジ時間 2,348 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
    while (b) {
        ll c = b;
        b = a % b;
        a = c;
    }
    return a;
}

int main() {
    ll N, M;
    cin >> N >> M;

    ll G = gcd(N, M);
    N /= G;
    M /= G;

    while (N % 10 == 0)
        N /= 10;

    while (M % 10 == 0)
        M /= 10;
    while (M % 2 == 0) {
        M /= 2;
        N *= 5;
        if (N % 10 == 0)
            N /= 10;
        N %= 10;
    }
    while (M % 5 == 0) {
        M /= 5;
        N *= 2;
        if (N % 10 == 0)
            N /= 10;
        N %= 10;
    }

    if (M != 1) N = -1;
    cout << N << endl;
}
0