public LinEquation Solve(LinEquation y) { LinEquation le = new LinEquation(); le.a = a * y.a; le.b = b + a * (y.b); return(le); }
public override string SolveTask2(string InputData) { List <ModEquation> equations = GetEquations(InputData); LinEquation prevEq = new LinEquation() { a = 1, b = 0 }; // TODO for (int i = 0; i < equations.Count; i++) { LinEquation tmpEq = equations[i].Solve(prevEq); prevEq = prevEq.Solve(tmpEq); } BigInteger res = prevEq.Solve(0); return($"{res}"); }
public LinEquation Solve(LinEquation eq) { BigInteger b = res - eq.b; if (b < 0) { b = (b % mod) + mod; } BigInteger inverse = BigInteger.ModPow(eq.a, mod - 2, mod); BigInteger r = b * inverse; LinEquation newLE = new LinEquation(); newLE.a = mod; newLE.b = r % mod; return(newLE); }