// Date: 2011-05-12 Khu

package Problems2Generic;
// Only to be used for extensions of Problem and Solution.

public class GcdProblemQAI extends DivisibleProblemQAI<GcdSolution>
{
    private GcdSolution solution;

    private int p, q, r, s;

    protected void checkSolvability ()
    {
        if (s == 0)
        {
            isDirectlySolvable = true;
            solution.set(r);
        }
    }

    protected void divide ()
    {
        assert !isDirectlySolvable : "precondition";
        int t = r % s;
        r = s;
        s = t;
    }

    public GcdSolution solution () {return solution;}

    public int p () {return p;}
    public int q () {return q;}

    public void set (int p, int q)
    {
        this.p = p;
        this.q = q;
        r = Math.abs(p);
        s = Math.abs(q);
        isDirectlySolvable = false;
        computeSolution();
    }

    public GcdProblemQAI ()
    {
        solution = new GcdSolution();
    }
}