結果

問題 No.25 有限小数
ユーザー tonyu0tonyu0
提出日時 2019-12-24 11:12:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 899 bytes
コンパイル時間 2,987 ms
コンパイル使用メモリ 164,292 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 17:00:50
合計ジャッジ時間 1,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::Read;

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: u64 = itr.next().unwrap().parse().unwrap();
    let mut m: u64 = itr.next().unwrap().parse().unwrap();

    let g: u64 = gcd(n, m);
    let mut m2: u32 = 0;
    let mut m5: u32 = 0;
    n /= g;
    m /= g;

    while m % 2 == 0 {
        m /= 2;
        m2 += 1;
    }
    while m % 5 == 0 {
        m /= 5;
        m5 += 1;
    }
    if m != 1 {
        println!("-1");
    } else {
        if m2 > m5 {
            n *= 5u64.pow(m2 - m5);
        } else if m5 > m2 {
            n *= 2u64.pow(m5 - m2);
        }
        while n % 10 == 0 {
            n /= 10;
        }
        println!("{}", n % 10);
    }
}
0