//! # Host Prime Seach //! //! Compute the next smaller prime //! use std::time::Instant; fn is_prime (a : u128) -> bool { if a % 2 == 0 {return false}; for i in (3..a.isqrt()).step_by(2) { if a % i == 0 { return false; } } return true; } fn find_next_smaller_prime(mut x : u128) -> u128 { if x <= 1 {return x}; if x % 2 == 0 {x=x-1}; while !is_prime(x) {x = x - 2}; return x; } fn main() { let n = 1<<56; println!("What is the next prime number smaller than {}?", n); let now = Instant::now(); let p = find_next_smaller_prime(n); let duration = now.elapsed(); println!("Found: {}. This took {:?}.", p, duration); } // End of file