LoginSignup
0
0

More than 3 years have passed since last update.

法nに基づく整数aの逆数を計算するプログラム

Last updated at Posted at 2020-02-03

invert of integer

def inv(a, n)

  d = n
  x = 0
  s = 1
  while (a != 0)
    q = d / a
    r = d % a
    d = a
    a = r
    t = x - q * s
    x = s
    s = t
  end
  gcd = d  # $\gcd(a, n)$ 

  return ((x + n) % (n / d))
end
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0