結果

問題 No.25 有限小数
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 20:14:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 42,868 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 07:19:18
合計ジャッジ時間 2,917 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<limits>

inline int count(long long& n, int x){
    int res = 0;
    while(n % x == 0){res += 1; n /= x;}
    return res;
}

long long expr(long long a, int n){
    long long res = 1ll;
    while(n > 0){
        if(n & 1){res *= a;}
        a *= a;
        n >>= 1;
    }
    return res;
}

int main(){
    long long N, M;
    scanf("%lld %lld", &N, &M);

    long long g = std::__gcd(N, M);
    N /= g;
    M /= g;

    int n2 = count(M, 2), n5 = count(M, 5);
    if(M != 1){
        puts("-1");
        return 0;
    }

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

    int a = std::max(n2, n5) - n2,
        b = std::max(n2, n5) - n5,
        c = std::min(a, b);

    printf("%lld\n", N * expr(2, a-c) * expr(5, b-c) % 10);
}
0