如何更改我的代码以除法求解模块化方程式?

问题描述

我写了扩展的欧几里得算法,但是用它来解决以下方程时遇到了麻烦:

(743360//1008//x)=272 (mod 1009)

Modular Equation Solver减少为

743360/1008x = 272 (mod 1009)

x == 116

这是我的代码:

def fastlinearcongruenceSO(powx,divmodx,N,withstats=False): 
 x,y,z = egcditerx2SO(powx,withstats) 
 answer = (y*divmodx)%N 
 if withstats == True: 
    print(f"answer = {answer}") 
 if x > 1: 
    powx//=x 
    divmodx//=x 
    N//=x 
    if withstats == True: 
      print(f"powx = {powx},divmodx = {divmodx},N = {N}") 
    x,withstats) 
    if withstats == True: 
      print(f"x = {x},y = {y},z = {z}") 
    answer = (y*divmodx)%N 
    if withstats == True: 
       print(f"answer = {answer}") 
 return answer

def egcditerx2SO(a,b,withstats=False): 
  s = 0 
  r = b 
  old_s = 1 
  old_r = a 
  quotient = 0
  if withstats == True: 
      print(f"quotient = {quotient},old_r = {old_r},r = {r},old_s = {old_s},s = {s}") 
  while r!= 0: 
    quotient = old_r // r 
    old_r,r = r,old_r - quotient * r 
    old_s,s = s,old_s - quotient * s 
    if withstats == True: 
      print(f"quotient = {quotient},s = {s}") 
  if b != 0: 
    bezout_t = quotient = (old_r - old_s * a) // b 
    if withstats == True: 
      print(f"bezout_t = {bezout_t}") 
  else: 
    bezout_t = 0 
  if withstats == True: 
    print("Bézout coefficients:",(old_s,bezout_t)) 
    print("greatest common divisor:",old_r) 
  return old_r,old_s,bezout_t

为求逆,我使用这种形式:

IN: fastlinearcongruenceSO(327,1,1009)
OUT: 108

我不确定要对它进行修改以使用除法形式进行解决,我不知道该如何或进行什么更改,是否有人对我需要进行哪些更改有任何想法,或者我是否可以使用现有代码解决它?我真的很想修改我的代码以解决以下方程:743360/1008x = 272 (mod 1009)x == 116或让某人让我知道该方程是如何求解的,然后我可以通过这些步骤修改我的代码以求解用于基于除法的模量方程。感谢所有知道如何求解这些基于除法方程的人。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...