Skip to content

Instantly share code, notes, and snippets.

@Shariar-Hasan
Last active February 8, 2023 21:52
Show Gist options
  • Save Shariar-Hasan/389bc57a2613e32e3f431a02f7e1edf7 to your computer and use it in GitHub Desktop.
Save Shariar-Hasan/389bc57a2613e32e3f431a02f7e1edf7 to your computer and use it in GitHub Desktop.
A python program for finding all the prime numbers till 10^6
'''
this program is for finding all the prime number till 10^6
if you want to print N'th prime number, type below code in last part of the solve() function
if you want to create more prime numbers, change the power of the big_val variable
`
print(primeList[n-1])
`
'''
def primeMake(big):
sus_prime = 2
while(sus_prime * sus_prime <= big):
if(primes[sus_prime]):
primeList.append(sus_prime)
for i in range(sus_prime*sus_prime, big+1, sus_prime):
primes[i] = False
sus_prime+=1
big_val = 10**6
primes = [True] * (big_val + 1)
primes[0] = primes[1] = False
primeList = []
primeMake(big_val)
def solve():
n = int(input())
print(primeList)
solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment