Tool to check if a number is a prime number. A primality test is a mathematical and algorithmic test that indicates whether a number is prime or compound and answers true or false.

dCode is free and its tools are a valuable help in games, puzzles and problems to solve every day! You have a problem, an idea for a project, a specific need and dCode can not (yet) help you? You need custom development? Contact-me!

Tool to check if a number is a prime number. A primality test is a mathematical and algorithmic test that indicates whether a number is prime or compound and answers true or false.

Answers to Questions

How to know if a number is a prime?

To know if a number is prime, it need to check if it has any divisor except 1 or itself, this test is called a primality test.

Example: Is 23456789 a prime number ? True

Example: Is 123456789 a prime number ? False

What are primality tests algorithms?

It exists several test to know if a number is a prime number : Miller–Rabin or Lucas-Lehmer are the one used by dCode.

What is the prime numbers test algorithm?

The algorithm tries all or almost all numbers (it avoids even numbers and multiples of 3). Here is a pseudo code applicable for prime numbers not too large: function is_prime(n) { if n ≤ 1 return FALSE else if n ≤ 3 return TRUE else if (n mod 2 = 0) or (n mod 3 = 0) return FALSE i = 5 while (i*i ≤ n) { if (n mod i = 0) or (n mod (i + 2) = 0) return FALSE i = i + 6 } return TRUE

Ask a new question

Source code

dCode retains ownership of the source code of the script Primality Test online. Except explicit open source licence (indicated Creative Commons / free), any algorithm, applet, snippet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in any informatic langauge (PHP, Java, C#, Python, Javascript, etc.) which dCode owns rights can be transferred after sales quote. So if you need to download the online Primality Test script for offline use, for you, your company or association, see you on contact page !

dCode uses cookies to customize the site content, analyze user behavior and adapt dCode to your use. Some data is stored and collected for advertising purposes and may be shared with our partners. OK