math/fermat_little_theorem: update proof statement#2641
Closed
pikulet wants to merge 2 commits intoTheAlgorithms:masterfrom
pikulet:math-fermat-little-theorem
Closed
math/fermat_little_theorem: update proof statement#2641pikulet wants to merge 2 commits intoTheAlgorithms:masterfrom pikulet:math-fermat-little-theorem
pikulet wants to merge 2 commits intoTheAlgorithms:masterfrom
pikulet:math-fermat-little-theorem
Conversation
pikulet
commented
Oct 2, 2020
| b = 10 | ||
|
|
||
| # using binary exponentiation function, O(log(p)): | ||
| print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p) |
Contributor
Author
There was a problem hiding this comment.
This was the previous check done!
pikulet
commented
Oct 2, 2020
| @@ -1,12 +1,24 @@ | |||
| # Python program to show the usage of Fermat's little theorem in a division | |||
| # According to Fermat's little theorem, (a / b) mod p always equals | |||
| # a * (b ^ (p - 2)) mod p | |||
Contributor
Author
There was a problem hiding this comment.
This is the original definition the author was working with. It's very convoluted and a is unnecessary in this equation (appears once on both LHS and RHS)
kbakdev
approved these changes
Oct 22, 2020
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Describe your change:
From wikipedia, the definition of fermat little theorem is that a**p = a (mod p)
In the old code, the author checked if:
(a/b) == a * (b**(p-2)) (mod p)
This is a rather convoluted way of expressing the fermat little theorem, which only involves two params a and p in the first place. The equivalent transformation was to do b**2/a to the original LHS and RHS.
I have also added the demonstration code for the special case when a is not divisible by p, then:
a**(p-1) = 1 (mod p)
Checklist:
Fixes: #{$ISSUE_NO}.