結果
問題 | No.1653 Squarefree |
ユーザー | fukafukatani |
提出日時 | 2021-08-22 21:07:00 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,171 bytes |
コンパイル時間 | 13,783 ms |
コンパイル使用メモリ | 382,312 KB |
実行使用メモリ | 11,416 KB |
最終ジャッジ日時 | 2024-11-06 20:09:08 |
合計ジャッジ時間 | 21,800 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 7 ms
6,816 KB |
testcase_02 | AC | 7 ms
6,816 KB |
testcase_03 | AC | 7 ms
6,820 KB |
testcase_04 | AC | 7 ms
6,820 KB |
testcase_05 | AC | 7 ms
6,820 KB |
testcase_06 | AC | 7 ms
6,816 KB |
testcase_07 | AC | 7 ms
6,816 KB |
testcase_08 | RE | - |
testcase_09 | AC | 7 ms
6,820 KB |
testcase_10 | AC | 8 ms
6,816 KB |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 263 ms
11,340 KB |
testcase_14 | AC | 269 ms
11,136 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 270 ms
11,168 KB |
testcase_18 | RE | - |
testcase_19 | AC | 263 ms
11,236 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | WA | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | AC | 273 ms
11,216 KB |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | WA | - |
testcase_34 | AC | 252 ms
11,244 KB |
testcase_35 | AC | 263 ms
11,264 KB |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 8 ms
6,816 KB |
testcase_40 | AC | 7 ms
6,816 KB |
コンパイルメッセージ
warning: unused variable: `ng` --> src/main.rs:35:22 | 35 | let (ok, ng) = binary_search(0, l + 1, |m| m * m <= num); | ^^ help: if this is intentional, prefix it with an underscore: `_ng` | = note: `#[warn(unused_variables)]` on by default
ソースコード
fn main() { let v = read_vec::<i64>(); let (l, r) = (v[0], v[1]); let primes = get_primes(1000001); let mut flags = vec![true; (r - l) as usize + 1]; let mut numbers = (l..=r).collect::<Vec<_>>(); for p in primes { let mut cur = (l / p) * p; if cur < l { cur += p; } while cur <= r { let idx = (cur - l) as usize; let mut count = 0; while numbers[idx] % p == 0 { numbers[idx] /= p; count += 1; } if count >= 2 { flags[idx] = false; } cur += p; } } let mut ans = 0; for num in l..=r { if num == 1 { ans += 1; continue; } if flags[(num - l) as usize] { let (ok, ng) = binary_search(0, l + 1, |m| m * m <= num); if ok * ok != num { ans += 1; } } } println!("{}", ans); } type Input = i64; fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input) where F: Fn(Input) -> bool, { assert_eq!(criterion(lb), true); assert_eq!(criterion(ub), false); let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid) { ok = mid; } else { ng = mid; } } (ok, ng) } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn get_primes(n: i64) -> Vec<i64> { let mut is_prime = vec![true; n as usize + 1]; let mut primes = Vec::new(); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i as usize] { primes.push(i); let mut j = 2 * i; while j <= n { is_prime[j as usize] = false; j += i; } } } primes }