Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reed_solomon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
darius.briquet
reed_solomon
Merge requests
!9
Resolve "Remake Modular inverse"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Remake Modular inverse"
10-remake-modular-inverse
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
jonas.stirnema
requested to merge
10-remake-modular-inverse
into
main
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#10 (closed)
Edited
3 years ago
by
jonas.stirnema
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
25edc1e9
1 commit,
3 years ago
1 file
+
15
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
inverse_mult.py
+
15
−
5
Options
# Created : 06/12/2021
# Refactored : 09/12/2021
import
math
from
euclide
import
*
# Get the multiplicvative inverse of a Mod p
# x = Multiplicative inverse of a mod p:
# a * x mod p = 1
def
inverse_mult
(
a
,
p
)
:
c
=
abs
(
a
^-
1
%
p
)
if
(
p
-
c
+
abs
(
a
)
==
1
):
return
c
return
False
pgcd
,
x
,
y
=
pgcd_etendu
(
a
,
p
)
if
pgcd
!=
1
:
return
None
if
a
>
p
:
return
x
else
:
return
y
if
__name__
==
"
__main__
"
:
print
(
inverse_mult
(
3
,
11
))
\ No newline at end of file
Loading