class Polynome
{
	protected Monome[] monomes;
	
	public Polynome()
	{
	}
	
	public Polynome(int c0)
	{
		this(new int[]{c0});
	}
	
	public Polynome(int c1, int c0)
	{
		this(new int[]{c1, c0});
	}
	
	public Polynome(int c2, int c1, int c0)
	{
		this(new int[]{c2, c1, c0});
	}
	
	public Polynome(int c3, int c2, int c1, int c0)
	{
		this(new int[]{c3, c2, c1, c0});
	}
	
	public Polynome(int c4, int c3, int c2, int c1, int c0)
	{
		this(new int[]{c4, c3, c2, c1, c0});
	}
	
	public Polynome(int[] coefficients)
	{
		monomes = new Monome[coefficients.length];
		for (int i=0; i <monomes.length; i++)
		{
			monomes[i] = new Monome(coefficients[i], i);
		}
	}
	
	public int coefAt(int i)
	{
		return monomes[i].getCoef();
	}
	
	public int expAt(int i)
	{
		return monomes[i].getExp();
	}
	
	public String toString()
	{
		String resultat = "", x;
		for (int i=monomes.length-1; i>=0; i--)
		{
			x = ""+monomes[i];
			if ((i != monomes.length-1) && (!x.equals("")) && (x.charAt(0) != '-'))
				resultat += "+";
			resultat += x;
		}
		return resultat;
	}
	
	public int calcul(int x)
	{
		int resultat = 0, puissance = 1;
		for (int i=0; i <monomes.length; i++)
		{
			resultat += coefAt(i)*puissance;
			puissance *= x;
		}
		return resultat;
	}
	
	public Polynome derivee()
	{
		Polynome resultat = new Polynome();
		resultat.monomes = new Monome[monomes.length-1];
		for (int i=1; i<monomes.length; i++)
			resultat.monomes[i-1] = new Monome(expAt(i)*coefAt(i), i-1);
		return resultat;
	}
	
	public Polynome somme(Polynome p)
	{
		Polynome resultat = new Polynome();
		int lengthThis = monomes.length, lengthP = p.monomes.length,
		min = Math.min(lengthThis, lengthP), max = Math.max(lengthThis, lengthP);
		resultat.monomes = new Monome[max];
		for (int i=0; i<min; i++)
			resultat.monomes[i] = new Monome(coefAt(i)+p.coefAt(i), i);
		for (int i=min; i<max; i++)
			if (lengthThis > lengthP)
				resultat.monomes[i] = monomes[i];
			else
				resultat.monomes[i] = p.monomes[i];
		return resultat;
	}
	
	public Polynome produit(Polynome p)
	{
		Polynome resultat = new Polynome();
		int lengthThis = monomes.length, lengthP = p.monomes.length;
		int degreMax = lengthThis + lengthP - 1, somme;
		resultat.monomes = new Monome[degreMax];
		for(int i=0; i<degreMax; i++)
		{
			somme = 0;
			for (int j=0; j<=i; j++)
			{
				if (j<lengthThis && (i-j) < lengthP)
					somme += coefAt(j)*p.coefAt(i-j);
				resultat.monomes[i] = new Monome(somme, i);
			}
		}
		return resultat;
	}
	
}
