結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | umnc |
提出日時 | 2021-09-14 13:26:28 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,900 bytes |
コンパイル時間 | 12,978 ms |
コンパイル使用メモリ | 395,684 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-27 03:10:33 |
合計ジャッジ時間 | 20,307 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 991 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 9 ms
5,376 KB |
testcase_12 | AC | 897 ms
5,376 KB |
testcase_13 | AC | 390 ms
5,376 KB |
testcase_14 | AC | 425 ms
5,376 KB |
testcase_15 | AC | 573 ms
5,376 KB |
testcase_16 | AC | 166 ms
5,376 KB |
testcase_17 | AC | 27 ms
5,376 KB |
testcase_18 | AC | 74 ms
5,376 KB |
testcase_19 | AC | 1,025 ms
5,376 KB |
testcase_20 | AC | 247 ms
5,376 KB |
testcase_21 | AC | 1,173 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 99 ms
5,376 KB |
ソースコード
#![allow(dead_code)] #![allow(unused_imports)] #![allow(unused_mut)] #![allow(unused_macros)] #![allow(unused_variables)] #![allow(non_upper_case_globals)] #![allow(non_snake_case)] #![allow(unused_unsafe)] #![allow(unused_must_use)] use std::cmp::*; use std::collections::*; use std::io::{self, stdout, BufRead, BufWriter, Write}; macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } macro_rules! dd { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("\x1b[38;5;39m|\x1b[m \x1b[38;5;39m", stringify!($a), " =\x1b[m {:?} "),*, "\x1b[38;5;69m|\x1b[m \x1b[38;5;6m"), $(&$a),*); }; } macro_rules! w { ($output:expr, $x:expr) => { let _ = writeln!($output, "{}", $x); }; } fn sumr(l: usize, r: usize) -> usize { let sm = (l + r) * (r - l + 1) / 2; return sm; } // fn is_prime(x: usize) -> bool { // if x < 2 { // return false; // } // if x == 2 || x == 3 || x == 5 { // return true; // } // if x % 2 == 0 || x % 3 == 0 || x % 5 == 0 { // return false; // } // let mut prime = 7.; // let mut step = 4.; // while prime <= (x as f64).sqrt() { // if x as f64 % prime == 0. { // return false; // } // prime += step; // step = 6. - step; // } // return true; // } fn is_prime_miller(n: u64) -> bool { if n <= 1 { return false; } else if n <= 3 { return true; } else if n % 2 == 0 { return false; } let pow = |r: u64, mut m: u64| -> u64 { let mut t = 1u128; let mut s = (r % n) as u128; let n = n as u128; while m > 0 { if m & 1 == 1 { t = t * s % n; } s = s * s % n; m >>= 1; } t as u64 }; let mut d = n - 1; let mut s = 0; while d % 2 == 0 { d /= 2; s += 1; } const B: [u64; 7] = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]; for &b in B.iter() { let mut a = pow(b, d); if a <= 1 { continue; } let mut i = 0; while i < s && a != n - 1 { i += 1; a = (a as u128 * a as u128 % n as u128) as u64; } if i >= s { return false; } } true } fn main() { let out = stdout(); let mut out = BufWriter::new(out.lock()); input!(l: usize, r: usize); let mut ans = 0; for i in l..=r { for j in 0..2 { let sm = sumr(i, i + j); if is_prime_miller(sm as u64) { ans += 1; } } } writeln!(out, "{}", ans); }