Cod sursa(job #412553)

Utilizator georgelRector George georgel Data 5 martie 2010 20:03:06
Problema Ecuatie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<fstream>
#include<math.h>

using namespace std;

ofstream fout("ecuatie.out");

long a,b,c,k,p;
void read()
{
	ifstream fin("ecuatie.in");
	
fin>>a>>b>>c>>k;

fin.close();
}
void function2( long m, long n)
{
 long i,j;
	for(i = abs(c); i >= -abs(c); i--)
		for(j = abs(c); j >= -abs(c); j--)
			if(i*j == c)
				if(m*i == b - j*n)
				{
					p++;
					if(p == k)
					{
						if(n ==1)
							fout<<"(x";
						else if(n == -1)
							fout<<"(-x";
						else
						fout<<"("<<n<<"x";
						if(i < 0)
							fout<<"-"<<-1*i<<")";
						else
							fout<<"+"<<i<<")";//fout<<"da";
						if(m == 1)
							fout<<"(x";
						else if(m == -1)
							fout<<"(-x";
						else
						fout<<"("<<m<<"x";
						if(j < 0)
							fout<<"-"<<-1*j;
						else
							fout<<"+"<<j;
						fout<<")";
						
					}
				}
}
void function()
{
    long i,j;
	for(i = -abs(a);  i <= abs(a) ;i++)
		for(j = -abs(a); j <= abs(a); j++)
			if(i*j == a)
			{
				//fout<<i<<" "<<j<<"\n";
				function2(i,j);
			}
}
int main()
{
	read();
	function();
fout.close();

return 0;

}