Struct Factorization

Source
pub struct Factorization;
Expand description

§Prime Factorization

This struct is used to factor large numbers and return their largest prime factor

use num_primes::{Generator,Factorization};
 
fn main() {
    // Generates New Unsighed Integer of 64 bits
    let uint = Generator::new_uint(64);
    // Prime Factorization    
    let prime_factor = Factorization::prime_factor(uint);
 
    match prime_factor {
        Some(x) => println!("Largest Prime Factor: {}",x),
        None => println!("No Prime Factors Found"),
    }
}

Implementations§

Source§

impl Factorization

Source

pub fn prime_factor(n: BigUint) -> Option<BigUint>

§Prime Factorization

This is a method of factoring the largest prime factors of large numbers. It is slow and should not be relied on. It can easily factor 32-bit numbers and sometimes 64-bit.

It returns as a Option<BigUint> type

use num_primes::{Generator,Factorization};
 
fn main() {
    // Generates New Unsighed Integer of 32 bits
    let uint = Generator::new_uint(32);
    // Prime Factorization    
    let factor = Factorization::prime_factor(uint);
 
    match factor {
        Some(factor) => println!("Largest Prime Factor: {}",factor),
        None => println!("No Prime Factors Found"),
    }
}
Examples found in repository?
examples/factorization.rs (line 8)
3fn main() {
4    // Generates New Unsighed Integer of 32 bits
5    let uint = Generator::new_uint(32);
6    
7    // Prime Factorization    
8    let factor = Factorization::prime_factor(uint);
9
10    match factor {
11        Some(factor) => println!("Largest Prime Factor: {}",factor),
12        None => println!("No Prime Factors Found"),
13    }
14}

Auto Trait Implementations§

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.