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
ismaelkno: 2024-03-11 06:28:01

AC AFTER 7 WA'S IZI PIZI BRUH PUT STRONGER CASES I FALL ASLEEP ZZZZZ

quarkeby3: 2024-01-10 10:50:35

learn the Miller Rabin Primality tests [cp-algorithms], easy in one go

Last edit: 2024-01-10 10:50:57
hoangziet22: 2023-12-17 13:51:00

Why is it TLE ?????
<snip>
[Simes]: don't post code here, use the forum.

Last edit: 2023-12-21 21:51:26
trumcspkkk6969: 2022-11-17 17:14:23

1 time miller rabin also get ac

gekko_code: 2021-04-16 06:42:23

Try to use deterministic Miller Rabin algorithm, it only takes 0.01sec for this problem.

Last edit: 2021-04-16 06:43:05
houda_bh: 2021-02-13 12:31:54

time limit exceeded what to do ?

mamun_01_neub: 2020-10-22 20:53:27

why it is run time error?

chikku: 2020-08-06 21:56:17

Use Miller Rabin Test, and get AC..

vayuhu: 2020-08-02 10:34:40

Why is primality test of sqrt(N) is throwing TLE?

[NG]: Because sqrt(max_n) = 2^32.

Last edit: 2020-08-02 15:01:19
mehul007: 2020-07-26 00:23:40

0.00 sec with miller rabin


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