Code Monkey home page Code Monkey logo

primalitytest's Introduction

PrimalityTest

primality test (Miller Rabin) implement by C#,
transplantation from a C Language Library Mpir

Features

  1. use System.Numerics.BigInteger (NET4 and later) support any size integer (Memory allowable).
  2. for input < 1000000, use determinate algorithm, The result is accurate.

How to

  1. import system.numerics.dll and add BigIntegerEx.cs file to your project

  2. 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;
}

Some Test Data

Online Prime Numbers Generator and Checker

Table of Mersenne Prime

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

Preview

Click to View

primalitytest's People

Contributors

iol0ol1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.