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
SangKuan: 2015-07-03 14:28:27

AC but still do not understand then Miller rabin

kartikay singh: 2015-06-05 20:46:08

JUST 1 ITERATION OF MILLER RABIN :)
check for overflows Costed me a WA...

_R0b_: 2015-04-26 22:33:44

go with : - > Miller rabin

Madhav: 2015-04-09 18:38:13

miller rabin works!!

Sayak Haldar: 2015-03-10 08:37:19

This problem has weak test cases....there is no checking for pseudoprimes (like 9,2047. etc)

Last edit: 2015-03-11 17:45:27
Abhinandan Agarwal: 2015-01-23 22:08:16

Accepted with Miller Rabin , but failed with Fermat's probability test ...
Any help ? Anyone who solved it using fermat's little theorem ?

lovecode: 2015-01-18 05:54:22

learned a new thing............AC finally

Last edit: 2015-01-18 05:55:07
Kriti Joshi: 2014-10-25 10:40:02

So much to learn in a single ques!! adorable, but 0 point

Last edit: 2014-10-25 10:40:38
Mitch Schwartz: 2014-08-20 09:50:35

@Archit Kapoor: Most likely the problem is on your end. It doesn't make sense to report that your code with irrelevant edits gets a different result from your original code; it is easy enough just to resubmit the original code. Using non-deterministic methods can cause different results when submitting identical code; you have not mentioned whether this could be an issue with your code or not. There is a difference between calling problems easy and actually demonstrating competence. You could try asking about it on the forum.

Archit Kapoor: 2014-08-20 08:24:22

Is there some problem with this..?? Because when I submitted my solution-it firstly gave wrong answer..this is a damn easy question and my code is well tested on my PC..Next I edited my code and just added few braces(irrelevantly) because I could not see why possibly my solution is giving wrong answer..and then again submitted...This time it is saying TLE..!!


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