#![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::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($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); }