結果
問題 |
No.152 貯金箱の消失
|
ユーザー |
|
提出日時 | 2016-08-10 18:59:21 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 191 ms / 5,000 ms |
コード長 | 680 bytes |
コンパイル時間 | 12,840 ms |
コンパイル使用メモリ | 379,004 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 08:46:48 |
合計ジャッジ時間 | 13,617 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
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); }