public
Created

  • Download Gist
euler.rs
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#[link(name = "euler", vers = "0.1")];
 
fn is_prime(n: int) -> bool {
 
let flt: float = n as float;
let sroot: int = float::sqrt(flt) as int;
let i = 3;
let rbool = true;
 
if n == 1 || (n > 2 && n % 2 == 0) {
false
}
else {
 
while ( i <= sroot ) {
if n % i == 0 {
rbool = false;
break;
}
i += 2;
}
rbool
}
}
 
// compile
// rustc --lib euler.rs
 
// $ time ./isprime 36413321723440003717
// 36413321723440003717 is prime
// real 0m0.075s
// user 0m0.002s
// sys 0m0.005s

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.