Last active
June 1, 2017 13:59
-
-
Save mariomartinezsz/b626554bfa3298a0651d3a8d5f30d207 to your computer and use it in GitHub Desktop.
Primality Test v1 with Rust (School Method)
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
// Time complexity of this solution is O(√n) | |
fn is_prime(n : i32) -> bool { | |
if n <= 1 { | |
return false; | |
} | |
for i in 2..n-1{ | |
if n%i == 0 { | |
return false; | |
} | |
} | |
return true; | |
} | |
fn main() { | |
let n = 3003; | |
println!("Number {} is prime? {}", n, is_prime(3003)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment