pub struct SieveN2PlusNPlus1 { /* private fields */ }
Expand description

$n^2+n+1$ 型素数の篩。

Idea

todo!()

References

Implementations§

source§

impl SieveN2PlusNPlus1

source

pub fn new(n: usize) -> Self

初期化する。

source

pub fn primes(&self) -> impl Iterator<Item = usize> + '_

$n^2+n+1$ の形の素数を返す。

Examples
use nekolib::math::SieveN2PlusNPlus1;

let ss = SieveN2PlusNPlus1::new(10);
let primes: Vec<_> = ss.primes().collect();
assert_eq!(primes, [3, 7, 13, 31, 43, 73]);
source

pub fn is_prime(&self, n: usize) -> bool

$n^2+n+1$ が素数のとき真を返す。

Examples
use nekolib::math::SieveN2PlusNPlus1;

let ss = SieveN2PlusNPlus1::new(10);
assert!(ss.is_prime(3));  // 13 is prime
assert!(!ss.is_prime(4));  // 21 = 3 * 7
source

pub fn factors(&self, n: usize) -> impl Iterator<Item = (usize, u32)> + '_

$n^2+n+1$ を素因数分解する。

底の昇順とは限らないので注意。

Examples
use nekolib::math::SieveN2PlusNPlus1;

let ss = SieveN2PlusNPlus1::new(20);
assert_eq!(ss.factors(0).next(), None);
assert_eq!(ss.factors(7).collect::<Vec<_>>(), [(3, 1), (19, 1)]);
assert_eq!(ss.factors(18).collect::<Vec<_>>(), [(7, 3)]);
source

pub fn factors_dup(&self, n: usize) -> impl Iterator<Item = usize> + '_

$n^2+1$ を素因数を列挙する。重複あり。

底の昇順とは限らないので注意。

Examples
use nekolib::math::SieveN2PlusNPlus1;

let ss = SieveN2PlusNPlus1::new(20);
assert_eq!(ss.factors_dup(0).next(), None);
assert_eq!(ss.factors_dup(6).collect::<Vec<_>>(), [43]);
assert_eq!(ss.factors_dup(18).collect::<Vec<_>>(), [7, 7, 7]);

Trait Implementations§

source§

impl Clone for SieveN2PlusNPlus1

source§

fn clone(&self) -> SieveN2PlusNPlus1

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SieveN2PlusNPlus1

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V