// Implementation file: GcdProblemQAI.cpp
// Date: 2011-05-12 Khu

#include "GcdProblemQAI.hpp"
#include <cassert>
#include <cstdlib>

	void GcdProblemQAI::check_solvability ()
	{
		if (s == 0)
		{
			is_directly_solvable = true;
			_solution->set(r);
		}
	}

	void GcdProblemQAI::divide ()
	{
		assert(!is_directly_solvable); // precondition
		int t = r % s;
		r = s;
		s = t;
	}

	void GcdProblemQAI::set (int new_p, int new_q)
	{
		_p = new_p;
		_q = new_q;
		r = abs(_p);
		s = abs(_q);
		is_directly_solvable = false;
		compute_solution();
	}

	GcdProblemQAI::GcdProblemQAI ()
	{
		_solution = new GcdSolution();
	}
	
	GcdProblemQAI::~GcdProblemQAI ()
	{
		delete _solution;
	}
