結果
問題 | No.407 鴨等素数間隔列の数え上げ |
ユーザー | cympfh |
提出日時 | 2016-08-28 00:01:32 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 30 ms / 1,000 ms |
コード長 | 1,992 bytes |
コンパイル時間 | 11,864 ms |
コンパイル使用メモリ | 406,932 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-05-09 12:10:03 |
合計ジャッジ時間 | 13,218 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 0 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 9 ms
5,376 KB |
testcase_21 | AC | 0 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 17 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 7 ms
5,376 KB |
testcase_33 | AC | 30 ms
6,784 KB |
testcase_34 | AC | 29 ms
6,912 KB |
testcase_35 | AC | 14 ms
5,376 KB |
コンパイルメッセージ
warning: unused import: `Write` --> src/main.rs:1:22 | 1 | use std::io::{ self, Write }; | ^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `min` --> src/main.rs:3:17 | 3 | use std::cmp::{ min, max }; | ^^^ warning: unused import: `BinaryHeap` --> src/main.rs:4:25 | 4 | use std::collections::{ BinaryHeap, VecDeque }; | ^^^^^^^^^^ warning: unused macro definition: `trace` --> src/main.rs:6:14 | 6 | macro_rules! trace { | ^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `swap` --> src/main.rs:11:14 | 11 | macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } | ^^^^ warning: variable `L` should have a snake case name --> src/main.rs:28:9 | 28 | let L: i32 = sc.cin(); | ^ help: convert the identifier to snake case: `l` | = note: `#[warn(non_snake_case)]` on by default
ソースコード
use std::io::{ self, Write }; use std::str::FromStr; use std::cmp::{ min, max }; use std::collections::{ BinaryHeap, VecDeque }; macro_rules! trace { ($var:expr) => ({ let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var); }) } macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } fn prime_sieve(n: usize) -> Vec<bool> { let mut s = vec![true; n]; s[0] = false; s[1] = false; for i in 2..n { if i * i > n { break } if s[i] { for k in 2..(n+i-1)/i { s[k * i] = false } } } s } fn main() { let mut sc = Scanner::new(); let n: i32 = sc.cin(); let L: i32 = sc.cin(); let ps = prime_sieve((L / (n - 1) + 10) as usize); let mut ans: u64 = 0; for d in 2..(L/(n-1)+1) { if !ps[d as usize] { continue } // trace!(d); // trace!(max(0, L - d * (n-1) + 1)); ans += max(0, L - d * (n-1) + 1) as u64; } println!("{}", ans); } #[allow(dead_code)] struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } } fn reserve(&mut self) { while self.buffer.len() == 0 { let mut line = String::new(); let _ = self.stdin.read_line(&mut line); for w in line.split_whitespace() { self.buffer.push_back(String::from(w)); } } } fn cin<T: FromStr>(&mut self) -> T { self.reserve(); match self.buffer.pop_front().unwrap().parse::<T>() { Ok(a) => a, Err(_) => panic!("parse err") } } fn get_char(&mut self) -> char { self.reserve(); let head = self.buffer[0].chars().nth(0).unwrap(); let tail = String::from( &self.buffer[0][1..] ); if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); } head } }