Skip to content

Instantly share code, notes, and snippets.

@JellyWX
Created April 6, 2018 10:18
Show Gist options
  • Save JellyWX/ec9fb139ce38d9b6c6d5dc1fd058eee9 to your computer and use it in GitHub Desktop.
Save JellyWX/ec9fb139ce38d9b6c6d5dc1fd058eee9 to your computer and use it in GitHub Desktop.
const int size = 1000000;
int main()
{
bool li[size] = {false};
for ( int i = 2; i < size; ++i )
{
if ( !li[i] )
{
for ( int j = i *2; j < size; j += i )
{
li[j] = true;
}
}
}
}
def sieve():
li = [True for _ in range(1000000)]
for i in range(2, len(li)):
if li[i] == True:
for j in range(i * 2, len(li), i):
li[j] = False
return li
sieve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment