Created
May 20, 2018 21:44
-
-
Save ikzekly/6d4bfd93e1a8ad745d0ab4b444ef71da 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 nth(n: u32) -> Option<u32> { | |
pub fn is_prime(n: u32) -> bool { | |
if n == 1 {return false}; | |
if n == 2 {return true}; | |
let sqrt_n = ((n as f32).sqrt() as u32) + 1; | |
for i in 2..sqrt_n { | |
if n % i == 0 {return false}; | |
} | |
true | |
} | |
let mut primes = Vec::new(); | |
while primes.len() < n as usize { | |
for n in 0..100000000 { | |
if is_prime(n) { primes.push(n); } | |
} | |
} | |
Some(primes[n as usize +1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment