Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

How to convert a modular arithmetic equation to python code?

(x/y) mod n = ((x mod n) * (y mod n)^-1) mod n

I would like to know how to convert the above statement into python.

question from:https://stackoverflow.com/questions/66068631/how-to-convert-a-modular-arithmetic-equation-to-python-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do something like this,

consider,

x=10
y=5
n=2
# You can use if condition to evaluate the expression
if (x/y)%n==((x%n)*(y%n)**(-1)):
    print('Condition satisfied')
else:
    print('Condition not satisfied')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...