可以使用gcd
和mod
函数完成此操作,如下所示:
A = 151; M = 541;
[G, C, ~] = gcd(A,M);
if G==1 % The inverse of a(mod b) exists only if gcd(a,b)=1
ModMultInv = mod(C,M)
else disp('Modular multiplicative inverse does not exist for these values')
end
<强>输出: - 强>
ModMultInv =
43