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
//! # YAPL
//!
//! `YAPL` (Yet Another Prime Library) is a collection of commands to test and
//! get prime numbers.

/// Test to see if the number given is prime.
///
/// # Examples
/// ```
/// let n = 7;
/// 
/// if(prime::isPrime(n))
/// {
///     println!("{}", n);
/// }

pub fn isPrime(n: u64) -> bool
{
    if n <= 1 { return false;}
    else if n <= 3 { return true;}
    else if n % 2 == 0 || n % 3 == 0 { return false;}

    let mut i = 5;
    while i * i <= n
    {
        if n % i == 0 || n % (i + 2) == 0 { return false;}
        i += 6;
    }
    return true
}