BlueBook - Prime

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 16M

Problem types
BlueBook

Given T (1 \le T \le 10\,000) integers N (1 \le 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 Specification

Line 1: one integer T
Lines 2 \dots T+1: one integer N

Output Specification

Lines 1 \dots 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

Comments


  • 0
    gavin_chen  commented on March 6, 2022, 7:42 p.m.

    I am using Python 3 and I got a TLE, I used PyPy 3 and it says it is "failed initializing" someone help


    • 0
      Plasmatic  commented on March 9, 2022, 10:21 p.m.

      Failed initializing is probably because you ran out of memory. Pypy uses a lot of memory.


    • 0
      Spitfire720  commented on March 7, 2022, 12:53 p.m.

      My assumption for you getting TLE is that you have iterated through each number in the test case. There is a faster way to test if a number is prime.


      • -1
        gavin_chen  commented on March 8, 2022, 12:12 a.m.

        I will look into that