結果
問題 | No.407 鴨等素数間隔列の数え上げ |
ユーザー | aimy |
提出日時 | 2017-10-24 10:22:40 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 50 ms / 1,000 ms |
コード長 | 2,833 bytes |
コンパイル時間 | 12,528 ms |
コンパイル使用メモリ | 383,964 KB |
実行使用メモリ | 9,512 KB |
最終ジャッジ日時 | 2024-11-21 17:35:00 |
合計ジャッジ時間 | 14,488 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 1 ms
6,820 KB |
testcase_15 | AC | 1 ms
6,816 KB |
testcase_16 | AC | 1 ms
6,816 KB |
testcase_17 | AC | 1 ms
6,816 KB |
testcase_18 | AC | 1 ms
6,820 KB |
testcase_19 | AC | 5 ms
6,820 KB |
testcase_20 | AC | 14 ms
6,820 KB |
testcase_21 | AC | 1 ms
6,820 KB |
testcase_22 | AC | 1 ms
6,816 KB |
testcase_23 | AC | 0 ms
6,820 KB |
testcase_24 | AC | 1 ms
6,820 KB |
testcase_25 | AC | 25 ms
6,816 KB |
testcase_26 | AC | 1 ms
6,816 KB |
testcase_27 | AC | 1 ms
6,816 KB |
testcase_28 | AC | 1 ms
6,820 KB |
testcase_29 | AC | 1 ms
6,820 KB |
testcase_30 | AC | 1 ms
6,820 KB |
testcase_31 | AC | 1 ms
6,820 KB |
testcase_32 | AC | 12 ms
6,816 KB |
testcase_33 | AC | 50 ms
9,476 KB |
testcase_34 | AC | 49 ms
9,512 KB |
testcase_35 | AC | 23 ms
6,816 KB |
ソースコード
use prime::*; fn main() { let (n, l): (usize, usize) = get::tuple(); let d = l / (n-1); let ps = primes(d); let ans = ps.iter().map(|p|l-p*(n-1)+1).sum::<usize>(); println!("{}", ans) } #[allow(dead_code)] mod prime { pub fn is_prime(n: usize) -> bool { let sq = (n as f64).sqrt().floor() as usize; let p = (2..sq+1).all(|d| n%d != 0); p } pub fn primes(n: usize) -> Vec<usize> { if n < 2 {return vec![]} let mut ps = vec![true; n+1]; ps[0] = false; ps[1] = false; for i in 2 .. n+1 { if ps[i] { for k in 2 .. n/i+1 { ps[i*k] = false; } } } ps.iter().enumerate().filter(|&(_,&p)|p).map(|(i,_)|i).collect() } pub fn factorize(n: usize) -> Vec<usize> { let sq = (n as f64).sqrt().floor() as usize; let mut fs = vec![]; let mut x = n; for d in 2 .. sq+1 { if x == 1 {break} while x > 1 && x % d == 0 { fs.push(d); x /= d; } } if x != 1 {fs.push(x)}; fs } } #[allow(dead_code)] mod get { use std::io::*; use std::str::*; pub fn val<T: FromStr>() -> T { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().parse::<T>().ok().unwrap() } pub fn vals<T: FromStr>(n: usize) -> Vec<T> { let mut vec: Vec<T> = vec![]; for _ in 0 .. n { vec.push(val()); } vec } pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); (x, y) } pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> { let mut vec: Vec<(T1, T2)> = vec![]; for _ in 0 .. n { vec.push(tuple()); } vec } pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); let mut it = buf.trim().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); let z = it.next().unwrap().parse::<T3>().ok().unwrap(); (x, y, z) } pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> { let mut vec: Vec<(T1, T2, T3)> = vec![]; for _ in 0 .. n { vec.push(tuple3()); } vec } pub fn list<T: FromStr>() -> Vec<T> { let mut buf = String::new(); stdin().read_line(&mut buf).ok(); buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() } pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> { let mut mat: Vec<Vec<T>> = vec![]; for _ in 0 .. h { mat.push(list()); } mat } }