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

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

hide comments
2013-10-23 20:52:39 AlcatraZ
Nice problem.. Learned something new.


Last edit: 2013-10-30 00:06:54
2013-09-22 17:16:30 P_Quantum
Nice one..!! Learned a lot..:)
2013-08-26 16:13:37 The Terminator
acc in little fermat
don't forget to use long long
2013-08-16 20:21:00 Dragan MarkoviƦ
Fermat's primality test is awesome.
2013-08-15 17:00:21 Lakshay Singhal
gr8 question...learnt smthng new
@hariprasath:ans for 9223372036854775783 is NO....
2013-06-17 09:13:33 Bharath Reddy
1 iteration Miller Rabin enough..
Great question!!
2013-06-02 16:16:02 Himanshu
really very good question learn a lot....
need 2 iterations of little fermit theorm.
thnaks to TOPCODER
2013-05-19 20:26:17 Chandan Mittal
using MR test..
all my answers are correct
but still getting WA here :(

AC :) just had an integer overflow problem

Last edit: 2013-05-21 23:37:09
2013-05-04 12:34:57 ওয়াসী (Wasi)
AC at 1st submission with Miller_Rabin algo...:D
Nice problem!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.