public static void _Main() { Mint a = new Mint(7); Mint b = new Mint(6); Console.WriteLine($"{a}+{b}:" + (a + b).Value); Console.WriteLine($"{b}-{a}:" + (b - a).Value); Console.WriteLine($"{a}*{b}:" + (a * b).Value); Console.WriteLine($"{a}/{b}:" + (a / b).Value); Console.WriteLine($"Pow(2,10):" + Mint.Pow((Mint)2, 10)); long x, y; var gcd = ExtGcd(11, 7, out x, out y); }
public static Mint Pow(Mint a, long n) { if (n == 0) { return(new Mint(1)); } Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) { b *= a; } return(b); }
public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return(new Mint(x)); }