+ 10

Challenge: How many prime numbers are in 100 000?

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In example: 2, 3, 11, 19, 23, 739. You need to find out how many are there in 100 000, but it would be great if you can go through a greater number, given that sololearn has an execution time limit (for anything other than web). So the trick is to make it fast! Some samples: 1-10: 4 1-100: 25 1-10000: 1229 My try: https://code.sololearn.com/cFt13s2PufPP/#cs

16th Dec 2017, 4:47 PM
MuzzRK
MuzzRK - avatar
15 Antworten
+ 14
Using Sieve of Eratosthenes algorithm : https://code.sololearn.com/c85hc4aSlXCK/?ref=app
15th Dec 2017, 10:19 AM
LukArToDo
LukArToDo - avatar
12th Dec 2017, 10:41 AM
DAB
DAB - avatar
+ 7
https://code.sololearn.com/cTMwGZ3gY0D4/?ref=app
12th Dec 2017, 11:43 AM
Andrew
Andrew - avatar
+ 5
Answer is: 9592 My Ruby try: https://code.sololearn.com/cqAXr6IscAgb/#rb
17th Dec 2017, 5:35 AM
noobcøder
noobcøder - avatar
+ 4
9592
12th Dec 2017, 6:07 PM
Eric Blinkidu
Eric Blinkidu - avatar
18th Dec 2017, 5:40 AM
Marcus Loh
Marcus Loh - avatar
+ 1
There's only one way to know for sure ;)
11th Dec 2017, 5:10 PM
MuzzRK
MuzzRK - avatar
+ 1
9,592 ?
12th Dec 2017, 11:54 AM
Faisur Ali
Faisur Ali - avatar
+ 1
yep, but that's not the point
12th Dec 2017, 12:01 PM
MuzzRK
MuzzRK - avatar
+ 1
Two implementations. Second one goes to n=1.000.000 without problem https://code.sololearn.com/cOAK88Tgl2QJ/?ref=app
12th Dec 2017, 9:14 PM
VcC
VcC - avatar
+ 1
Bonus : list of all primes <n one liner https://code.sololearn.com/cjluzxU72b4t/?ref=app
12th Dec 2017, 9:30 PM
VcC
VcC - avatar
+ 1
https://code.sololearn.com/c47a9XM7pUpk/?ref=app Here is mine 😎😎🤗
22nd Feb 2018, 10:42 AM
Nashat
Nashat - avatar