結果

問題 No.1352 Three Coins
ユーザー tonyu0tonyu0
提出日時 2021-01-17 14:42:04
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 899 bytes
コンパイル時間 12,111 ms
コンパイル使用メモリ 385,260 KB
実行使用メモリ 238,408 KB
最終ジャッジ日時 2024-05-07 06:01:44
合計ジャッジ時間 15,909 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 10 ms
6,816 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;
use std::io::*;
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn rec(x: u64, a: u64, b: u64, c: u64, st: &mut HashSet<u64>) {
    if x >= a * b * c || st.contains(&x) {
        return;
    }
    st.insert(x);
    rec(x + a, a, b, c, st);
    rec(x + b, a, b, c, st);
    rec(x + c, a, b, c, st);
}

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 a: u64 = itr.next().unwrap().parse().unwrap();
    let b: u64 = itr.next().unwrap().parse().unwrap();
    let c: u64 = itr.next().unwrap().parse().unwrap();
    if gcd(a, gcd(b, c)) != 1 {
        println!("INF");
    } else {
        let mut st = HashSet::<u64>::new();
        rec(0, a, b, c, &mut st);
        println!("{}", a * b * c - st.len() as u64);
    }
}
0