Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdding algorithm to check if number is prime or not. #834
Conversation
|
@kvedala Modified the code as per the changes you have suggested. |
Please see the files changes in #807 - The comment blocks, and structure is per the GCC suggests -
Also, if you want to optimize further, you can have the line# 12 loop condition to go only till |
|
|
|
looks good |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


omkarlanghe commentedJun 7, 2020
My first contribution to this repository contains algorithm to check if the given number is prime or not.
Small description on how I have optimized the logic:
Reduced all possibilities of a number which cannot be prime.
Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+2 jumping on all odd numbers only.
If number is <= 1 or if it is even except 2, break the loop and return false telling number is not prime.