結果
| 問題 | No.1352 Three Coins | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-01-17 14:42:04 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 899 bytes | 
| コンパイル時間 | 12,498 ms | 
| コンパイル使用メモリ | 377,876 KB | 
| 実行使用メモリ | 638,828 KB | 
| 最終ジャッジ日時 | 2024-11-29 20:18:28 | 
| 合計ジャッジ時間 | 72,042 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 15 TLE * 15 MLE * 4 | 
ソースコード
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);
    }
}
            
            
            
        