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
2020-05-15 14:42:39
Time limit exceeded on PY, but it fine works on IDEone
2020-04-04 20:29:45
I am using MIller Rabin Test but still getting wrong ans
any suggestions . My Sol id is 25696991
2020-03-28 01:56:32
What are the compile options for Rust, particularly the optimization level? When will be the next update?
2020-03-20 04:36:04
time limit is 21s and I got AC in 0.00s. is it because the server is much stronger than 15 years ago ? or the test cases are too weak ?
2019-11-23 18:23:10
Used Miller Rabbin. AC in one go :)
2019-08-14 12:32:46
i used farmat little theorem in C ,,,getting WA ,,
i m using big mod

why??can anyone tell me?
2019-07-06 14:13:20
#JavaCodersMatter :'(
2019-06-11 09:03:13
Works with just fermant's with 20 iterations and by taking care of overflow during multiplications
2019-05-18 11:08:42
useful links to solve the problem
1) https://cp-algorithms.com/algebra/primality_tests.html
2) https://www.geeksforgeeks.org/multiply-large-integers-under-large-modulo/
2019-05-14 09:00:56
Carmichael numbers may be giving you WA. Read this
https://crypto.stanford.edu/pbc/notes/numbertheory/millerrabin.html
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.