結果

問題 No.152 貯金箱の消失
ユーザー tshigtshig
提出日時 2016-08-10 18:59:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 200 ms / 5,000 ms
コード長 680 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 150,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:29:08
合計ジャッジ時間 1,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 30 ms
5,376 KB
testcase_08 AC 198 ms
5,376 KB
testcase_09 AC 200 ms
5,376 KB
testcase_10 AC 153 ms
5,376 KB
testcase_11 AC 83 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io;
use std::io::prelude::*;

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

fn run(args: &Vec<String>) -> i32 {
    let l: i32 = args[0].parse().expect("number is expected");
    let max_m = (l as f64).sqrt().floor() as i32;
    (2..(max_m + 1)).map(|m| {
        (1..m).filter(|n| {
            (m - n) % 2 == 1 && gcd(m, *n) == 1 && 8 * m * (m + n) <= l
        }).count() as i32
    }).fold(0, |sum, i| sum + i)
}

fn main() {
    let stdin = io::stdin();
    let args = stdin.lock().lines().map(|l| l.unwrap()).collect();
    let r = run(&args);
    println!("{}", r);
}
0