結果

問題 No.442 和と積
ユーザー atetubou
提出日時 2019-04-30 13:59:07
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 16,387 ms
コンパイル使用メモリ 378,800 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 22:43:02
合計ジャッジ時間 17,496 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> Vec<T>
where
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).unwrap();
    b.split_whitespace()
        .map(|x| x.trim().parse::<T>().unwrap())
        .collect()
}

fn gcd(x: u64, y: u64) -> u64 {
    let (x, y) = if x < y { (x, y) } else { (y, x) };
    if x == 0 {
        return y;
    }

    return gcd(x, y % x);
}

fn main() {
    let iv = read::<u64>();
    let a = iv[0];
    let b = iv[1];
    //let ag = gcd(a + b, a);
    //let bg = gcd(a + b, b);
    if a > 1 && a == b && (a & (a - 1)) == 0 {
        println!("{}", a + b);
        return;
    }
    println!("{}", gcd(a, b));
}
/*

x=a+b, a * b
xa = gcd(x, a)
xb = gcd(x, b)

x = k1 * xa
x = k2 * xb
a = k5 * xa
b = k6 * xb

xab = gcd(x, a*b) = gcd(a+b, a * b)
a*b = k4 * xab = (k5 * xa) * b = (k6*xb) * a
x = k3 * xab = k1 * xa = k2 * xb



*/
0