Java icon indicating copy to clipboard operation
Java copied to clipboard

Better way to check a number for Prime. Update PrimeCheck.java

Open ZingadePrathamesh opened this issue 1 year ago • 5 comments
trafficstars

The function does this by

  1. Skip even numbers (except 2) since they are not prime.
  2. Skip multiples of 3 after checking 3.
  3. Start checking for factors from 5 and use the 6k ± 1 optimization. This is based on the fact that any prime number greater than 3 can be expressed as 6k ± 1.

This helps to make it much more efficient for large numbers.

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized it.
  • [x] All filenames are in PascalCase.
  • [x] All functions and variable names follow Java naming conventions.
  • [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • [x] All new code is formatted with clang-format -i --style=file path/to/your/file.java

ZingadePrathamesh avatar Jun 27 '24 05:06 ZingadePrathamesh

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 51.20%. Comparing base (fa22317) to head (07368ad).

Files with missing lines Patch % Lines
.../main/java/com/thealgorithms/maths/PrimeCheck.java 0.00% 10 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5259      +/-   ##
============================================
- Coverage     51.25%   51.20%   -0.05%     
+ Complexity     3192     3191       -1     
============================================
  Files           524      524              
  Lines         15194    15204      +10     
  Branches       2893     2898       +5     
============================================
- Hits           7787     7785       -2     
- Misses         7084     7095      +11     
- Partials        323      324       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jun 27 '24 05:06 codecov-commenter

Please, fix formatting issues, and update branch, and we can start review.

alxkm avatar Aug 08 '24 07:08 alxkm

I don't know how to do format. This is my first pull request. I will try again soon

On Thu, 8 Aug 2024 at 13:23, Alex Klymenko @.***> wrote:

Please, fix formatting issues, and update branch, and we can start review.

— Reply to this email directly, view it on GitHub https://github.com/TheAlgorithms/Java/pull/5259#issuecomment-2275181336, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYJIQWW4MUIGE5IBHCW53SLZQMPX7AVCNFSM6AAAAABJ7EVAS2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZVGE4DCMZTGY . You are receiving this because you authored the thread.Message ID: @.***>

ZingadePrathamesh avatar Aug 09 '24 01:08 ZingadePrathamesh

I don't know how to do format. This is my first pull request. I will try again soon

Just run clang-format. If you are having problems with that, please inspect the log: https://github.com/TheAlgorithms/Java/actions/runs/9691003340/job/26741793012?pr=5259 It seams that you just need to remove some double spaces in few places - it can definitely be done manually.

vil02 avatar Aug 09 '24 18:08 vil02

I don't know how to do format. This is my first pull request. I will try again soon

Just run clang-format. If you are having problems with that, please inspect the log: https://github.com/TheAlgorithms/Java/actions/runs/9691003340/job/26741793012?pr=5259 It seams that you just need to remove some double spaces in few places - it can definitely be done manually.

I guess the code is good to go now.

ZingadePrathamesh avatar Aug 14 '24 07:08 ZingadePrathamesh