Prime

Struct Prime 

Source
pub struct Prime {}
Expand description

A struct that provides methods for prime factorization using pollard rho algorithm and testing primality of numbers.

Implementations§

Source§

impl Prime

Source

pub fn pollard(n: u64) -> u64

Pollard’s rho algorithm for integer factorization.

§Arguments
  • n - The number to factorize.
§Returns

A non-trivial factor of n.

§Time Complexity

The algorithm offers a trade-off between its running time and the probability that it finds a factor. A prime divisor can be achieved with a probability around 0.5, in O(?d) <= O(n^(1/4)) iterations. This is a heuristic claim, and rigorous analysis of the algorithm remains open.

Source

pub fn factor(n: u64) -> Vec<u64>

Factorizes n into its prime factors.

§Arguments
  • n - The number to factorize.
§Returns

A vector containing the prime factors of n in sorted order.

Source

pub fn is_prime(n: u64) -> bool

Checks if n is a prime number.

§Arguments
  • n - The number to check.
§Returns

true if n is prime, false otherwise.

Auto Trait Implementations§

§

impl Freeze for Prime

§

impl RefUnwindSafe for Prime

§

impl Send for Prime

§

impl Sync for Prime

§

impl Unpin for Prime

§

impl UnwindSafe for Prime

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.