Skip to content

Methods and extensions for prime number detection and discovery.

License

Notifications You must be signed in to change notification settings

Open-NET-Libraries/Open.Numeric.Primes

Repository files navigation

Open.Numeric.Primes

Methods and extensions for prime number detection and discovery.

NuGet

Examples

Importing

using Open.Numeric.Primes;

Primality Test

Number.IsPrime(8592868089022906369); // true

Factors

Prime.Factors(12); // 2, 2, 3

Common Factors

Prime.CommonFactors(84, 756, 108); // 2, 2, 3

Greatest Factor

Prime.GreatestFactor(84, 756, 108); // 12

Prime Discovery

// Will list the first 1000 primes.
foreach(var prime in Prime.Numbers.Take(1000))
{
    Console.Write(prime);
}

or

// Will list the first 1000 primes greater than (or equal to) 10,000.
foreach(var prime in Prime.Numbers.StartingAt(10000).Take(100))
{
    Console.Write(prime);
}

Extensions

Extensions are also available for integer types.

using Open.Numeric.Primes.Extensions;

8592868089022906369.IsPrime(); // true