For the next few problems of this series, you will be given a property
and a bunch of (usually
) numbers or expressions. Your answer will be an
-digit number, where
is the number of numbers or expressions given. For the
-th number or expression, if it satisfies property
, then on the
-th digit of your answer, enter
. If not, enter
as the
-th digit. For example, if
: even, and there are
numbers,
. Then, enter your answer as
.
: primes
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
There are many primality tests around. A simple and common algorithm is just checking weather any number below N divides the number. Unfortunately the large input of this problem renders it unusable.The Miller-Rabin test is an excellent primality test(atleast practically) and is based on the contrapositive of Fermat's little theorem ..
The test implemented in python below determines numbers 1 , 2 , 3 , 4 to be prime and the rest composite,hence the answer 1 2 3 4 0 0 0 0 .
EDIT:Note that the Miller Rabin test is randomized and is usually referred to as a probabilistic algorithm.More powerful deterministic algorithms such as AKS exist(Discovered in 2002, by Agrawal, Kayal, and Saxena) but Miller-Rabin is widely used because of its speed..