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^631]
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
Alex Tran:
20140630 03:53:46
my fermat primality implementation fails to recognize 32416187567 as prime..


Ashwini:
20140628 08:13:21
@Simarpreet You will need to write a new function for multiplication too apart from powering. Just think for a moment and you will get it. 

Ashwini:
20140628 08:09:06
AC in one go.. I can't believe :)


Soma:
20140625 01:42:58
worth solving...


simararorarox9:
20140622 04:13:54
it really works.. just one doubt, I did this program in python because.. In c++ it will get out of range when i find square using fast exponentiation method taking modulo at each step..How to avoid it. ? Last edit: 20140622 04:14:38 

shashi roshan:
20140526 19:01:35
fermat's test with 2 iteration is enough...dont forget to use long long / unsigned long long....test cases are weak..9223372036854775783 is prime, but my accepted solution shows it as notprime... 

excursionist:
20140520 22:19:42
TLE :(


[Lakshman]:
20140407 17:48:50
@Pratyush try to learn Rabin Miller.


.::.:
20140407 17:24:53
got too many WA


Anubhav Balodhi :
20140312 09:12:57
got a tle, got too many wa.

Added by:  Roman Sol 
Date:  20050124 
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 JSRHINO LUA NEM NICE PHP PIKE ST 
Resource:  ZCon 2005 