BlueBook

p299ex4: Prime

Given T (1 ≤ T ≤ 10000) integers N (1 ≤ N < 2^16), output "1" if each one is prime, and "0" otherwise.

Remember: an integer is prime iff (if and only if) it has exactly two divisors: 1 and N.

Input

Line 1: one integer T
Lines 2..T+1: one integer N

Output

Lines 1..T: One integer "1" or "0" denoting whether N is prime. Output "1" if N is prime, and "0" otherwise.

Sample Input

3
1
2
3

Sample Output

0
1
1

All Submissions
Best Solutions


Point Value: 4
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 27, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

My code works on my interpreter but not on the PEG Judge. Please tell me why.

Your code is clobbering up variables.

Look at the variable names you are using on lines 2, 5, 9. Then try rubber-ducking your code. What actually happens when it breaks out of the for loop (not what you intended, I assume)

Uhh... well I was scanning through the question and I think there's a typo.

"Remember: an integer is prime iff (if and only if) it has exactly two divisors: 1 and N."

I think it should be "if (if and only if) it has exactly two divisors: 1 and N." and not "iff (if and only if) it has exactly two divisors: 1 and N.".

iff is shorthand for "if and only if"
since having two divisors is sufficient and necessary for being prime, iff is the correct term here

edit: read here
https://en.wikipedia.org/wiki/If_and_only_if

why does it give me a traceback....
T_T
does it not allow modules?

The full traceback is as follows:

Traceback (most recent call last): 
File "./a", line 25, in
if prime == False:
NameError: name 'prime' is not defined

thanks ^^

My program is right, i tested it several times but the judge gives me 0/10?

Your program is completely wrong, and thinks that 9 is a prime number.

i dont like peg that much anymore...
wat does this mean:.../?
does anyone know a faster way to do prime? Mine keeps saying time limit exceeded so i need some help.
thnx:)

What don't you like? PEG, or the PEG Judge? If you don't like PEG, then quit. If you don't like the Judge, I'm open to suggestions on how to improve it.

You can make your program faster by noticing that when you check whether a number is prime, you only need to test for factors up to the square root of the number.


I just don't like the math part of PEG. I'm quite fond of programming.
And what does: .../ mean? (When you get answer wrong and you click details, or your output)

If you send me a screenshot I'll take a look.