62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use std::io;
|
|
|
|
fn make_seive(up_limit:usize) -> Vec<bool>{
|
|
let mut seive : Vec<bool> = vec![true; up_limit + 1];
|
|
let m = (up_limit as f64).sqrt().ceil() as usize;
|
|
|
|
seive[0] = false;
|
|
seive[1] = false;
|
|
|
|
for i in 2..m{
|
|
if seive[i] == true{
|
|
let mut j = i * i;
|
|
while j <= up_limit{
|
|
seive[j] = false;
|
|
j += i;
|
|
}
|
|
}
|
|
}
|
|
|
|
return seive;
|
|
}
|
|
|
|
fn main(){
|
|
let up_limit : usize = 10000;
|
|
let seive = make_seive(up_limit);
|
|
|
|
let mut line = String::new();
|
|
io::stdin().read_line(&mut line)
|
|
.expect("Failed to read line");
|
|
let low = line.trim().parse::<usize>().expect("Input is not a integer");
|
|
|
|
let mut line = String::new();
|
|
io::stdin().read_line(&mut line)
|
|
.expect("Failed to read line");
|
|
let up = line.trim().parse::<usize>().expect("Input is not a integer");
|
|
|
|
let (mut S, mut min) : (usize, usize) = (0, 0);
|
|
|
|
for p in low..up+1{
|
|
if seive[p] == true{
|
|
S += p;
|
|
min = p;
|
|
break;
|
|
}
|
|
}
|
|
if min != 0{
|
|
for p in min+1..up+1{
|
|
if seive[p] == true{
|
|
S += p;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if S == 0{
|
|
println!("-1");
|
|
}
|
|
else{
|
|
println!("{}\n{}", S, min);
|
|
}
|
|
}
|