-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp3.rs
More file actions
29 lines (27 loc) · 740 Bytes
/
p3.rs
File metadata and controls
29 lines (27 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main(){
let val = 600851475143;
let val_isqrt = (val as f64).sqrt() as usize + 1;
// println!("size: {}",val_isqrt);
let mut vals = vec![true; val_isqrt];
for i in 2..val_isqrt {
// println!("val {}",i);
if vals[i] {
// println!("oth {}",(val_isqrt/i) as usize);
for j in 2..( (val_isqrt/i) as usize + 1) {
let ind = j*i;
// println!("ind {}",ind);
if ind < val_isqrt {
vals[ind] = false;
}
}
}
}
let mut it = vals.len() - 1;
loop {
if vals[it] && val % it == 0 {
println!("{}",it);
break;
}
it = it-1;
}
}