結果
問題 | No.1653 Squarefree |
ユーザー | koba-e964 |
提出日時 | 2021-09-15 22:48:52 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,167 bytes |
コンパイル時間 | 22,381 ms |
コンパイル使用メモリ | 378,880 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-06-29 00:48:59 |
合計ジャッジ時間 | 36,486 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 11 ms
5,248 KB |
testcase_02 | AC | 10 ms
5,376 KB |
testcase_03 | AC | 11 ms
5,376 KB |
testcase_04 | AC | 10 ms
5,376 KB |
testcase_05 | AC | 11 ms
5,376 KB |
testcase_06 | AC | 11 ms
5,376 KB |
testcase_07 | AC | 10 ms
5,376 KB |
testcase_08 | AC | 10 ms
5,376 KB |
testcase_09 | AC | 10 ms
5,376 KB |
testcase_10 | AC | 11 ms
5,376 KB |
testcase_11 | AC | 147 ms
11,648 KB |
testcase_12 | AC | 153 ms
11,648 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 19 ms
5,376 KB |
testcase_37 | AC | 19 ms
5,376 KB |
testcase_38 | AC | 19 ms
5,376 KB |
testcase_39 | AC | 19 ms
5,376 KB |
testcase_40 | AC | 19 ms
5,376 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } fn sqrt(x: i64) -> i64 { if x <= 1 { return x; } let mut pass = 0; let mut fail = 1 << 30; while fail - pass > 1 { let mid = (pass + fail) / 2; if mid * mid <= x { pass = mid; } else { fail = mid; } } pass } fn main() { const W: usize = 1_000_001; input!(l: i64, r: i64); let n = (r - l + 1) as usize; let mut pr = vec![true; W]; pr[0] = false; pr[1] = false; for i in 2..W { if !pr[i] { continue; } for j in 2..(W - 1) / i + 1 { pr[i * j] = false; } } let mut rem = vec![0; n]; let mut sq = vec![false; n]; for i in 0..n { rem[i] = l + i as i64; } for p in 2..W { let pp = p as i64; let mut x = (l + pp - 1) / pp * pp; while x <= r { let idx = (x - l) as usize; if x % (pp * pp) == 0 { sq[idx] = true; } else { rem[idx] /= pp; } x += pp; } } for i in 0..n { let x = sqrt(rem[i]); if x > 1 && rem[i] == x * x { sq[i] = true; } } println!("{}", sq.iter().filter(|&&x| !x).count()); }