【问题标题】:How to convert a modular arithmetic equation to python code?如何将模算术方程转换为python代码?
【发布时间】:2021-02-05 18:25:00
【问题描述】:
(x/y) mod n = ((x mod n) * (y mod n)^-1) mod n

我想知道如何将上面的语句转换成python。

【问题讨论】:

  • 您已经知道其中的哪些具体部分该怎么做?哪一部分你知道该怎么做?一般来说,你知道怎么做模吗?你做了什么研究?您与正确解决方案的距离有多近?
  • 另外,建立一个标题来谈论问题,而不是关于。目标是问题及其答案应该对遇到相同问题的每个人都有帮助,因此试图弄清楚如何做同样具体事情的其他人应该能够找到它并从它的答案中学习。
  • ...作为涵盖许多相同空间的预先存在的问题的示例,请参阅How to calculate a mod b in python? - 为防止此问题重复,这将有助于显示您卡在哪里尝试应用该预先存在的问题的答案时。

标签: python modular-arithmetic


【解决方案1】:

你可以这样做,

考虑,

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')

【讨论】:

  • 我不认为这就是他们的意思,但这是一个聪明的解释。不过,忘记了最后一个 %n。
猜你喜欢
  • 2022-12-30
  • 1970-01-01
  • 2018-09-10
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 2023-03-29
  • 2018-10-30
  • 1970-01-01
相关资源
最近更新 更多