Bluebook

Ten Primes on a Line

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, 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

All Submissions
Best Solutions


Point Value: 5
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)

Is there an upper bound on M?

Assume M < 10000.

Im printing ten to a line so what else am i doing wrong. PLEASE HELP!

Your algorithm for finding primes is incorrect. With your current algorithm 33 is considered a prime(it's not).

But when I run it through ideone.com, 33 doesn't print as a prime...

Sorry it was late so I thoughy of the wrong number. Try 493(17*29).

Ohh I see, it does print it thanks but I don't get how it's printing that

As I mentioned before, your algorithm for determining primes is incorrect. Here's a useful link that should help you.
https://en.wikipedia.org/wiki/Primality_test

Alright thanks

i got the 1st test case right but not the 2nd and 3rd

printing them ten to a line