Skip to content

Sieve of Eratosthenes optimization. #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2017
Merged

Conversation

izanbf1803
Copy link
Contributor

Complexity and space reduced to a half.

Complexity and space reduced to a half.
@ankit167
Copy link
Collaborator

The code gives wrong output for input- 0 and 1

assert(x >= 0)
# If x is even, exclude x from list (-1):
sieve_size = (x//2 - 1) if x % 2 == 0 else (x//2)
sieve = [1 for v in range(sieve_size)] # Sieve
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atleast two spaces before inline comment.

# If x is even, exclude x from list (-1):
sieve_size = (x//2 - 1) if x % 2 == 0 else (x//2)
sieve = [1 for v in range(sieve_size)] # Sieve
primes = [2] # List of Primes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atleast two spaces before inline comment.

if sieve[i] == 1:
value_at_i = i*2 + 3
primes.append(value_at_i)
for j in range(i, sieve_size, value_at_i):
sieve[j]=0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing white spaces around operator

@izanbf1803
Copy link
Contributor Author

Fixed error for input, spaces before comment and operator.

@ankit167 ankit167 merged commit d24f030 into keon:master May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants