// Date: 2011-05-12 Khu namespace Problems { class GcdProblemQAI : DivisibleProblemQAI { protected GcdSolution solution; protected int p, q, r, s; protected override void CheckSolvability () { if (s == 0) { isDirectlySolvable = true; solution.Set(r); } } protected override void Divide () { System.Diagnostics.Debug.Assert (!isDirectlySolvable, "precondition"); int t = r % s; r = s; s = t; } public override GcdSolution Solution () {return solution;} public int P {get {return p;}} public int Q {get {return q;}} public virtual void Set (int p, int q) { this.p = p; this.q = q; r = System.Math.Abs(p); s = System.Math.Abs(q); isDirectlySolvable = false; ComputeSolution(); } public GcdProblemQAI () { solution = new GcdSolution(); } } }