/Is-Prime

O(1) Algorithm to check if number is prime that works in 95%+ cases.

Primary LanguageHTMLOtherNOASSERTION

Is Prime

Welcome to the GitHub repository of an efficient algorithm that determines whether or not a given number is prime with 95% accuracy in constant time (O(1)). Prime numbers have always been an interesting topic in the field of mathematics and computer science, and detecting them with high accuracy and efficiency is a challenge that has been tackled by many researchers. This algorithm uses the fact that most of the numbers are not prime, to detect a prime number.

Contributing

If you want to help with this project, you can make a pull request with an implementation for a language that hasn't been added before, or at least by giving it a star.

Contributing guidelines

If it's at all possible, name the function: is_prime. For the main parent class in OO languages, you should also name it is_prime (of course, only if it's possible in that language). Also, when you implement in some new language, do remember to implement an optimized version, and add that language to the list at the bottom of the readme.

FAQ

Is this project serious?

Yes, this is a 100% serious project.

Where where does 95%+ come from?

When we take a random integer between 1 and 2,147,483,647, there are around 105,000,000 prime numbers. So, the chance that our number will be prime is ~4,88%.

How does the optimized implementation work?

Thecoderunsfasterwhentherearenouselessspacesandnewlines.

The algorithm has been implemented in these languages:

Arduino ArnoldC Assembly Brainfuck C C# C++ COW CUDA Clojure Coq Dart Elixir Elm English FStar Fortran 95 GO HTML+CSS Haskell Java Javascript Julia Kotlin Lisp Lua Markdown Matlab OCaml PHP Pascal Perl Piet Powershell Python R Rockstar Ruby Rust SQL Scala Solidity Swift Typescript Vhdl Zig