Playing Hacks and Stuffs!
Given an integer n
, return the number of prime numbers that are strictly less than n
.
The question is very straight forward and it’s clear on what we’re to do
First my approach was I needed to find a way to get all the numbers within n-1
range
And then iterating over the list and comparing if it’s less than n
which I’ll increase the counter is the statement if True
But I had problem with generating the list of prime numbers I suck at math which is bad :( so I looked at the hint and it gave the algorithm to use
Cool upon checking google on that I got this
With that algorithm Sieve of Eratosthenes we can get the list of prime numbers within a specific n
range
Then from that the remaining part is easy as we can just iterate through the prime numbers list and check for the condition
Here’s my solve script: link