BlueBook - 10 Primes on a Line

View as PDF

Submit solution

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

Problem types

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


Sample Output

2 3 5 7 11


  • 0
    Joao_Ribeiro  commented on Dec. 28, 2020, 8:38 p.m.

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

    • 1
      aegirwang  commented on Dec. 28, 2020, 9:36 p.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.

      • 2
        Joao_Ribeiro  commented on Dec. 28, 2020, 11:16 p.m.

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