Skip to content

Instantly share code, notes, and snippets.

@youknowcast
Created July 7, 2019 07:33
Show Gist options
  • Save youknowcast/0cbead4316713f34b17ef8a11c668d6a to your computer and use it in GitHub Desktop.
Save youknowcast/0cbead4316713f34b17ef8a11c668d6a to your computer and use it in GitHub Desktop.
eratosthenes with Rust
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