pair<Polynom, Polynom> Polynom::divide(const Polynom& _another) const {
	//cout << "i am divide(...)" << endl;
	pair<Polynom, Polynom> result(Polynom(), *this); //result and remainder
	result.first.simplify();
	result.second.simplify();

	while(result.second.pow() >= _another.pow() && (result.second.pow() != 0 || result.second[0] != 0)) {
		//cout << "result: " << result.first << endl;
		//cout << "reminder: " << result.second << endl;
		//cout << "divider: " << _another << endl;

		Polynom t;
		unsigned int i = result.second.pow() - _another.pow();
		t.a.resize(i + 1, 0);
		t.a[i] = result.second[result.second.pow()] / _another[_another.pow()];
		
		//cout << "multiplier: " << t << endl;
		//cout << "let's decrease on: " << t * _another << endl;
		//cout << endl << endl;

		result.first += t;
		result.second -= t * _another;
	}

	//cout << "Summary:" << endl;
	//cout << "result: " << result.first << endl;
	//cout << "reminder: " << result.second << endl;


	return result;
}
Polynom Polynom::operator * (const Polynom& _another) const {
	Polynom result;
	result.a.resize(pow() + _another.pow() + 1, Fraction(0, 1));
	for(int i = 0; i <= pow(); i++) {
		for(int j = 0; j <= _another.pow(); j++) {
			result.a[i+j] += a[i] * _another.a[j];
		}
	}

	return result;
}
bool Polynom::operator == (const Polynom& _another) const {
	if(pow() != _another.pow()) {
		return false;
	}

	Polynom tmp;
	if(a[pow()] != _another[_another.pow()]) {
		if(_another[_another.pow()] == 0) {
			return a[pow()] == 0;
		}
		tmp.a[0] = a[pow()] / _another[_another.pow()];
	}
	tmp *= _another;

	for(int i = 0; i < pow(); i++) {
		if(a[i] != tmp.a[i]) {
			return false;
		}
	}

	return true;
}
bool Polynom::operator <= (const Polynom& _another) const {
	return pow() <= _another.pow();
}
bool Polynom::operator > (const Polynom& _another) const {
	return pow() > _another.pow();
}