primality test (Miller Rabin) implement by C#,
transplantation from a C Language Library Mpir
- use System.Numerics.BigInteger (NET4 and later) support any size integer (Memory allowable).
- for input < 1000000, use determinate algorithm, The result is accurate.
-
import system.numerics.dll and add BigIntegerEx.cs file to your project
-
using namespace
using System.Numerics;
Sample 1
string input = "12345678656434565342324354651234567865643456534232435465";
/// 23 is Miller Rabin loop count
bool isPrime = BigInteger.Parse(input).IsPrime(23, out double a);
if(isPrime)
Trace.TraceInformation($"The probability of a prime number is {a}.");
else
Trace.TraceInformation("This is NOT prime.");
Sample 2
string input = "12345678656434565342324354651234567865643456534232435465";
int result = BigIntegerEx.IsPrime(BigInteger.Parse(input), 23);
switch (result)
{
case 0:
Trace.TraceInformation("This is NOT prime.");
break;
case 1:
Trace.TraceInformation("This is 'probably' prime");
break;
case 2:
Trace.TraceInformation("This is surely prime");
break;
default:
break;
}
Online Prime Numbers Generator and Checker
Some Carmichael Number
341,561,645,1105,1387,1389,1729,1905,2465,2821,6601,8911,
10585,15841,29341,41041,46657,52633,62745,63973,75361,
161038,215326,2568226,143742226