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

royanitra04on Jan 01, 2016 - 10:05:56 pm UTC Why am I getting it wrong?spencereiron Jan 01, 2016 - 10:28:44 pm UTC Re: Why am I getting it wrong?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)

royanitra04on Jan 01, 2016 - 10:04:27 pm UTC Typo maybe??"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.".

spencereiron Jan 01, 2016 - 10:26:28 pm UTC Re: Typo maybe??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

Dmen555on Apr 21, 2012 - 7:34:42 pm UTCT_T

does it not allow modules?

jargonon Apr 22, 2012 - 5:19:49 am UTC Re: ...Dmen555on Apr 22, 2012 - 6:33:06 pm UTC Re: Re: ...achal_parikhon Nov 16, 2011 - 3:57:54 am UTCbbi5291on Nov 16, 2011 - 4:06:46 am UTC Re: ...ilovepion Dec 01, 2010 - 12:35:34 am UTC wat's upwat does this mean:.../?

does anyone know a faster way to do prime? Mine keeps saying time limit exceeded so i need some help.

thnx:)

bbi5291on Dec 01, 2010 - 2:06:26 am UTC Re: wat's upYou 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.

GeerthanSrikantharajahon Dec 10, 2010 - 12:08:46 am UTC Re: Re: wat's upilovepion Feb 18, 2011 - 3:38:32 am UTC Re: Re: wat's upAnd what does: .../ mean? (When you get answer wrong and you click details, or your output)

bbi5291on Feb 18, 2011 - 8:58:43 pm UTC Re: Re: wat's up