結果

問題 No.25 有限小数
ユーザー tottoripaper
提出日時 2014-11-16 20:14:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 43,456 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 21:01:41
合計ジャッジ時間 1,413 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     scanf("%lld %lld", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

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