結果

問題 No.25 有限小数
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 20:16:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 860 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 43,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 22:50:18
合計ジャッジ時間 1,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 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 = res * a % 10ll;}
        a = a * a % 10ll;
        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) % 10ll);
}
0