Created
February 9, 2019 12:47
-
-
Save sireliah/24ae7ce5b9aafaa13ebcdfac494272bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| pub fn generate_primes(max: u64) -> Vec<u64> { | |
| let mut candidates: Vec<u64> = vec![1; max as usize + 1]; | |
| candidates[0] = 0; | |
| candidates[1] = 0; | |
| let max_sqrt = (max as f64).sqrt() as u64 + 1; | |
| for number in 2..max_sqrt { | |
| let mut multiplied = number * number; | |
| while multiplied < max + 1 { | |
| candidates[multiplied as usize] = 0; | |
| multiplied += number; | |
| } | |
| } | |
| candidates | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment