Skip to content

Instantly share code, notes, and snippets.

@mariomartinezsz
Last active June 1, 2017 13:59
Show Gist options
  • Save mariomartinezsz/b626554bfa3298a0651d3a8d5f30d207 to your computer and use it in GitHub Desktop.
Save mariomartinezsz/b626554bfa3298a0651d3a8d5f30d207 to your computer and use it in GitHub Desktop.
Primality Test v1 with Rust (School Method)
// 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