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
2014-08-20 09:50:35 Mitch Schwartz
@Archit Kapoor: Most likely the problem is on your end. It doesn't make sense to report that your code with irrelevant edits gets a different result from your original code; it is easy enough just to resubmit the original code. Using non-deterministic methods can cause different results when submitting identical code; you have not mentioned whether this could be an issue with your code or not. There is a difference between calling problems easy and actually demonstrating competence. You could try asking about it on the forum.
2014-08-20 08:24:22 Archit Kapoor
Is there some problem with this..?? Because when I submitted my solution-it firstly gave wrong answer..this is a damn easy question and my code is well tested on my PC..Next I edited my code and just added few braces(irrelevantly) because I could not see why possibly my solution is giving wrong answer..and then again submitted...This time it is saying TLE..!!
2014-08-05 17:57:40 Nitto Janitto
Not sure if I understood it right, but it seems like the method to determine if a number is prime or not is random, so could it be possible to get WA once, but get AC the second time without changing anything in the code?

Last edit: 2014-08-05 18:00:03
2014-07-07 23:37:06 Kapil Sethi
i used Miller algo and fast i/o but my time is 1.45 sec in c++.How can i further optimize to get better time? (like 0.0 :P)
2014-06-30 03:53:46 Alex Tran
my fermat primality implementation fails to recognize 32416187567 as prime..
2014-06-28 08:13:21 Ashwini
@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.
2014-06-28 08:09:06 Ashwini
AC in one go.. I can't believe :)
My first randomised algo program..

Last edit: 2014-06-28 08:09:47
2014-06-25 01:42:58 Soma
worth solving...
my first problem solved using probabilistic method..../
learnt a lot..
2014-06-22 04:13:54 simararorarox9
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: 2014-06-22 04:14:38
2014-05-26 19:01:35 shashi roshan
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 not-prime...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.