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)
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)
"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.".
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
T_T
does it not allow modules?
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:)
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.
And what does: .../ mean? (When you get answer wrong and you click details, or your output)