Next Semiprime

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Primes are no longer popular. Semiprimes are now trendy, and everyone wants one.

A semiprime is a number which has two prime factors, which do not need to be distinct. For example, the square of a prime is a semiprime.

The first few semiprimes are 4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33.

You have 1Q5104 friends you want to help out, numbered 1Q. Each friend has a number 1Nk109 where 1kQ.

For each friend, you are to find the smallest semiprime strictly greater than Nk.

Constraints

Subtask Q N % of points
1 10 103 1
2 100 104 2
3 100 106 4
4 1000 108 8
5 10000 109 15
6 50000 109 70

Input Specification

The first line will contain Q. The next Q lines will contain all N.

Output Specification

The corresponding semiprime for each N, one per line.

Sample Input

Copy
7
1
5
100
1000000000
100
123456
987654321

Sample Output

Copy
4
6
106
1000000006
106
123458
987654343

Explanation

Factor and see for yourself.


Comments


  • 0
    andrewtam  commented on Oct. 18, 2020, 2:32 p.m. edited

    Is prime factorization the right approach to this question? Do I just need to further optimize my code or should I try something different?


  • 26
    Chensta  commented on Dec. 30, 2017, 12:41 a.m.

    I wish I had 50 thousand friends


    • 6
      Riolku  commented on April 2, 2019, 12:27 p.m.

      I wish I had 1.


      • 9
        HyperNeutrino  commented on April 2, 2019, 1:48 p.m.

        just do what I do and get some imaginary ones. then just multiply them by i and you'll have some friends :D


        • 9
          Zeyu  commented on April 2, 2019, 2:35 p.m.

          Wait doesn't that get you a negative amount of friends 😥


          • 11
            p1geon  commented on April 2, 2019, 6:52 p.m.

            multiply by i two more times! problem solved 😎