BlueBook - 10 Primes on a Line

View as PDF

Submit solution

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

Problem types
BlueBook

A natural number N (greater than one), is a prime number if it has no natural number divisors other than 1 and N. Given an integer M (5 \le M \le 500), write a program that finds the first M primes, printing them ten to a line. Each number should be separated by a space.

Sample Input

5

Sample Output

2 3 5 7 11

Comments


  • 0
    Joao_Ribeiro  commented on Dec. 29, 2020, 1:38 a.m. edited

    Hi. what is the max value of M. I passed 2 out of 3 sets. I'm using sieve to solve this. My code.


    • 0
      aegirwang  commented on Dec. 29, 2020, 2:36 a.m.

      Your sieve sieves up to 1e6, but it only inserts primes up to the square root of that. You could either change the sieve size or just put another for loop after it to insert primes, instead of doing it both at once.


      • 0
        Joao_Ribeiro  commented on Dec. 29, 2020, 4:16 a.m. edited

        thank you so much! I added a for loop to add more primes and it passed :D thanks, aegirwang !