## 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.

```3
1
2
3```

### Sample Output

```0
1
1```

Point Value: 4
Time Limit: 2.00s
Memory Limit: 16M

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

• (0/0)
I tried testing it with multiple different numbers and it seems to work for me, but it always gives me a traceback error. What am I doing wrong?

• (0/0)
My code works on my interpreter but not on the PEG Judge. Please tell me why.

• (0/0)
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)

• (0/0)
rubber ducking???

• (1/0)

• (0/1)
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.".

• (0/0)
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

https://en.wikipedia.org/wiki/If_and_only_if

• (0/0)
why does it give me a traceback....
T_T
does it not allow modules?

• (0/0)
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 ``

• (0/0)
thanks ^^

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

• (1/0)
Your program is completely wrong, and thinks that 9 is a prime number.

• (0/0)
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:)

• (2/0)
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.

• (1/0)
I agree.

• (0/0)
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)

• (0/0)
If you send me a screenshot I'll take a look.