1

I wrote the Extended Euclidean Algorithm, but i'm having trouble with using it to solve the following equation:

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

which the Modular Equation Solver reduces to

743360/1008x = 272 (mod 1009)

and

x == 116

Here is my code:

def fastlinearcongruenceSO(powx, divmodx, N, withstats=False): 
 x, y, z = egcditerx2SO(powx, N, 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, y, z = egcditerx2SO(powx, N, 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}, old_r = {old_r}, r = {r}, old_s = {old_s}, 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

To solve for inverses, i used this form:

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

I'm not sure how or what changes i need to make to modify it to solve with the form of division, does anyone have any ideas of what changes i need to make or if i can solve it using my existing code? I really want to modify my code to handle it solving this equation: 743360/1008x = 272 (mod 1009) and x == 116 or for someone to let me know how that equation was solved, and i can then with those steps modify my code to solve for division based modulus equations. Thanks for anyone who knows how to solve these division based equations.

enter image description here

oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
  • I'm not familiar with the notation with two slashes. What is the binary operation that is denoted with two slashes. – President James K. Polk Aug 12 '20 at 13:12
  • @PresidentJamesK.Polk it;s a div. https://www.dcode.fr/modular-equation-solver reduces (7433660//1008//x)=272 (mod 1009) to 743360/1008x = 272 (mod 1009). I absolutely can't seem to use EGCD to solve this so hoping for some help. dcode.fr solves it as x=116 – oppressionslayer Aug 12 '20 at 13:28
  • The standard notation for division is a single slash. In python, there is a double slash operator that performs floored division. Your question is labelled python but the equation looks like a mixture of standard math notation with some python notation thrown in. Therefore I cannot figure out what the equation truly means. – President James K. Polk Aug 12 '20 at 13:31
  • @PresidentJamesK.Polk I added a picture at the bottom that might help – oppressionslayer Aug 12 '20 at 13:43
  • I can solve many linear congruences using egcd and egcd division, but this form with the division on the left i can't seem to figure out how to solve and want to write a program that will do so as dcode.fr can. I'm subscribed to wolfram alpha, but couldn't figure out how to input the equation to see if i could get a step by step solution – oppressionslayer Aug 12 '20 at 13:53
  • No, it doesn't help, because it doesn't explain why you used two slashes instead of one. The modular solver is just multiplying both side by x/272 to get the solution x=116. – President James K. Polk Aug 12 '20 at 14:25
  • I sortof solved it by doing this: 1009 - fastlinearcongruencex2(744360//1009,1, 1009) + 1 = 116 – oppressionslayer Aug 12 '20 at 14:41

0 Answers0