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
vishwanath_26:
20171024 21:12:29
Test cases may contain Carmichael numbers so use Miller Rabin 

wisdommm:
20171004 09:55:40
You need use both quick_pow and quick_multiply. 

amulyagaur:
20170725 11:25:37
accepted in 0.02 sec with only 2 iterations in fermat's test 

musfiq_mridha:
20170617 16:20:38
Is it solvable only using sieve with optimazation? Last edit: 20170617 16:20:53 

kspoj:
20170610 09:35:01
Guys, I've tried using Miller Rabin test as suggested, but my code's failing in this test case :


rohit9934:
20170508 16:02:07
The only thing that can screw you up is overflow WA 

caohoangtung:
20170401 19:50:06
First time using Miller Rabin :D learnt alot 

nilabja16180:
20170325 15:41:52
20 iteration gives 0.15 sec, 100 iteration produces result in 0.74 sec, 1000 iteration produces result in 7.84 sec! 

epsilonalpha:
20170314 20:49:32
0.05s with 7base deterministic Miller Rabin and 0.09s with 12base deterministic Miller Rabin in C++. :) 

thinkwise:
20170222 17:52:36
Ohh man why i am getting tle man

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 