【问题标题】:Math question on solving modular equations解模方程的数学题
【发布时间】:2020-11-28 23:17:15
【问题描述】:

我有以下模方程:

327????≡ ℎ*327*327*???? ≡ ℎ*327 ≡ 1 (mod 1009) and so

???? ≡ ℎ*327x ≡ ℎ*1 ≡ ℎ (mod 1009).

So I have to find out what ℎ is.

3*327=981≡-28(mod1009)

我不明白这里的 3 是如何推导出来的,你用什么公式来找到 3。

我知道 -28%1009 = 981,但我不知道作者是如何得出知道乘以 3 来得到一个答案,从而创建得到该数字的 mod。任何帮助将不胜感激

完整的公式在这里,我知道这可以用 EGCD 解决,但我试图了解作者如何以他的方式解决解决方案:

The question:

In [1505]: (327*327*108)%1009                                                                                                                                 
Out[1505]: 327
Only 108 (as far as i know( will return 327. So the equation is:

(327*327*x)%1009 = 327.  What is the quickest way to solve for this step by step. 
 ( What i don't understand is how the author solved for the 3 here in the step listed below ( 3*327 =981 ≡−28 (mod 1009) )

The Answer ( which worked )
gcd(327,1009)=1 so there is an ℎ so that 327∗ℎ≡1(mod1009) so if 327*327*????≡327(mod1009) then

327????≡ℎ*327*327*????≡ℎ*327≡1(mod1009) and so

????≡ℎ*327????≡ℎ*1≡ℎ(mod1009).

So I have to find out what ℎ is.

3 * 327 = 981 ≡ −28 (mod 1009)

327=28 * 12 − 9 so

327≡(−3 * 327) * 12 − 9 ( mod 1009 )

378 * 327≡−9 (mod 1009)

28=3 * 9 + 1

-3 * 327 ≡ 3 * (-37 * 327)+1 (mod 1009)

108* 327≡1 (mod 1009)

So ℎ≡108 and ????≡108 (mod 1009).

=====

And indeed 108* 327 *327=35316 *327= (1009 *35+1) *327=1009 *(35 *327)+327.

好的,根据回复,我想出了这个程序,它似乎可以验证结果:

def getmod4(A, N):
  multiplier = N//A
  a = A * multiplier
  b = -(N - a)
  va = b%N
  assert va == a

  # or, the next e,d can be done by a // b ??
  e = a // b #math.gcd((va|1)-1, (b|1)-1)
  #f = -(va//e)

  c = math.gcd((A|1)-1, (b|1)-1)
  c = abs(b)//c - c

  d = abs(b) * c - A

  assert ((-multiplier * A) * c - d)%N == A

  print(f"Equation: {abs(b)} * {c} - {d}:  {abs(b) * c - d}") 
  print(f"Verification: ((-{multiplier}*{A}) * {c} - {d})%{N} = {((-multiplier*A) * c - d)%N}")
  return abs(b) * c - d

结果:

In [3079]: getmod4(327,1009)                                                                                                                                  
Equation: 28 * 12 - 9:  327
Verification: ((-3*327) * 12 - 9)%1009 = 327
Out[3079]: 327

In [3081]: getmod4(261,10099)                                                                                                                                 
Equation: 181 * -20 - -3881:  261
Verification: ((-38*261) * -20 - -3881)%10099 = 261
Out[3081]: 261

【问题讨论】:

  • 我没有按照您发布的步骤进行操作。但是,由于gcd(327, 1009) == 1,存在整数a, b,使得327*a + 1009*b = 1,例如a = 108b = -35。然后将原方程乘以108,得到x
  • @dxiv,谢谢,我发布了完整的帖子。我只是不明白作者是如何解决这个步骤的,所以我只是想知道是否有人知道这个公式,因为我想按照他的解决方法编写一个程序。我编写了 EGCD 来解决这些问题,但我认为他的方法很有趣,值得我按照他的步骤编写一个程序来解决这些问题。所以我试图把他的步骤写进一个程序,但我坚持他是如何推导出 3 的。
  • 对不起,我还是没跟上。它的前半部分似乎只是将h 定义为327 的倒数(mod 1009)。在那之后,我认为它选择了3,以便3 * 327 接近1009,并修改数字以获得最终结果。不过,我看不出这会如何概括。
  • 我认为他的解决方案是基于数学论文或pdf数学论文,我只需要找到它,我真的想在程序中实现这个方法,因为我已经编写了很多程序找到线性同余和 egcd,但我认为这是一种新颖的方法,我想尝试为其编写程序,因为我对编写新程序来解决这些类型的问题非常感兴趣。模方程求解和不同的方法现在对我来说真的很有趣
  • 我投票结束这个问题,因为它是关于数学,而不是计算机编程。尝试数学交换。

标签: python math modulus arithmetic-expressions


【解决方案1】:

我不明白这里的 3 是如何得出的,你用什么公式来找到 3。

这只是division with remainder

计算 1009/327 得到大约 3.085626911。这告诉你 1009 = 3*327 + R,其中余数 R 小于 327。

【讨论】:

  • Joni,看看我的最新更新,你的建议奏效了,我写了一个验证方法来确保结果。我认为你一针见血,至少在我最初的测试中是这样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-15
  • 2020-05-31
  • 1970-01-01
相关资源
最近更新 更多