PON - Prime or Not


Given the number, you are to answer the question: "Is it prime?"

Solutions to this problem can be submitted in C, C++, Pascal, Perl, Python, Ruby, Lisp, Hask, Ocaml, Prolog, Whitespace, Brainf**k and Intercal only.

Input

t – the number of test cases, then t test cases follows. [t <= 500]
Each line contains one integer: N [2 <= N <= 2^63-1]

Output

For each test case output string "YES" if given number is prime and "NO" otherwise.

Example

Input:
5
2
3
4
5
6

Output:
YES
YES
NO
YES
NO

hide comments
vayuhu: 2020-08-02 10:34:40

Why is primality test of sqrt(N) is throwing TLE?

[NG]: Because sqrt(max_n) = 2^32.

Last edit: 2020-08-02 15:01:19
mehul007: 2020-07-26 00:23:40

0.00 sec with miller rabin

impulse15: 2020-07-23 20:25:01

can anyone provide the link of his code done by Fermat or miller method ??
i tried both but both gave the wrong answer

prasant35: 2020-07-14 23:47:59

how can i get AC in 0.00s ?my current best is 0.06s .

panther_786: 2020-07-14 09:28:22

Got AC with 2.68 sec using fermat's theorem.
Hint: Take care of overflow while multiplying.

Last edit: 2020-07-14 09:31:13
spoj_1105: 2020-06-23 07:08:20

my code was compiled in 14sec but still its showing tle. any suggestions why?

jpfr12: 2020-06-05 12:59:50

@sutharp777 sadly, we can not submit in Java or Kotlin.

lone_coderrr: 2020-06-05 09:50:16

Works great with Fermats little test just make sure to give it somewhere around 20 iteration, got AC in 0.10s using python!

sutharp777: 2020-05-29 13:57:41

in java it's easy just isProbablePrime(10) in java.math.BigInteger.

gr523: 2020-05-27 15:43:10

BigMod alone can not take care of overflow


Added by:Roman Sol
Date:2005-01-24
Time limit:21s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM32 BASH CSHARP CLPS D ERL FORTRAN ICON JAVA JS-RHINO LUA NEM NICE PHP PIKE ST
Resource:ZCon 2005