結果

問題 No.25 有限小数
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-19 21:37:24
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 143,460 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-29 02:32:47
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int main(){

    long long N, M, X, cnt2=0, cnt5=0, s;
    cin >> N >> M;
    if (N % M == 0){
        X = N/M;
        while(X != 0){
            if (X % 10 != 0){
                cout << X % 10 << endl;
                return 0;
            }
            X /= 10;
        }
    }

    while(M % 2 == 0){
        cnt2++;
        M /= 2;
    }
    while(M % 5 == 0){
        cnt5++;
        M /= 5;
    }

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

    while(N % 2 == 0 && cnt2 > 0){
        cnt2--;
        N /= 2;
    }
    while(N % 5 == 0 && cnt5 > 0){ 
        cnt5--;
        N /= 5;
    }

    if (cnt2 > 0) s = 5;
    else s = N % 10;
    
    while(cnt5 > 0){
        s = ((s * 10) / 5) % 10;
        cnt5--;
    }

    cout << s << endl;

    return 0;
}
0