Created
July 7, 2019 07:33
-
-
Save youknowcast/0cbead4316713f34b17ef8a11c668d6a to your computer and use it in GitHub Desktop.
eratosthenes with Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let num: usize = 100000; | |
let mut prime = vec![1; num+1]; | |
let limit: usize; | |
for i in 2..num { | |
prime[i] = 1; | |
} | |
limit = ((num as f64).sqrt() as usize); | |
for i in 2..limit { | |
if prime[i] == 1 { | |
for j in i*2..num { | |
if j % i == 0 { | |
prime[j] = 0; | |
} | |
} | |
} | |
} | |
for i in 2..num { | |
if prime[i] == 1 { | |
println!("{}", i); | |
} | |
} | |
println!("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment