結果

問題 No.25 有限小数
ユーザー face4face4
提出日時 2018-10-25 14:53:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 534 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 63,804 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-04-29 21:36:28
合計ジャッジ時間 7,216 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;
typedef long long ll;

bool check(ll m){
    while(m % 5 == 0)   m /= 5;
    while(m % 2 == 0)   m /= 2;
    return m == 1;
}

int main(){
    ll n, m;
    cin >> n >> m;

    if(!check(m)){
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    while(n){
        ans = n/m;
        n %= m;
        n *= 10;
    }

    if(ans >= 10){
        ll ten = 10;
        while(ans%ten == 0) ten*=10;
        ans = (ans%ten)*10/ten;
    }

    cout << ans << endl;
    
    return 0;
}
0