title: How to efficiently find coefficients of a polynomial from its roots?
body: <p>Given are the <code>n</code> roots of a polynomial whose leading coefficient is 1.
  How do I <em>efficiently</em> find out the coefficients of this polynomial?</p>
  
  <p>Mathematically,
  I know that if the first coefficient is 1, then sum of product roots taken <code>k</code> at a time will be the <code>k+1-th</code> coefficient of the polynomial.</p>
  
  <p>My code is based on this approach.</p>
  
  <p>In other words, how to optimally find the sum of product of numbers from a list taken <code>k</code> at a time.</p>
  
  <pre><code>int main()
  {
  
      int n, sum;
      cin &gt;&gt; n;
      int a[n];
      for (int i=0; i&lt;n; i++) cin &gt;&gt; a[i];
      //for the second coefficient
      sum=0;
      for (int i=0; i&lt;n; i++)
      {
          sum+=a[i];
      }
      cout &lt;&lt; sum &lt;&lt; endl;
      //for the third coefficient
      sum=0;
      for (int i=0; i&lt;n; i++)
      {
          for (int j=i+1; j&lt;n; j++)
          {
              sum+=a[i]*a[j];
          }
      }
      cout &lt;&lt; sum &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I have thought of marking the numbers on whether I have taken them into the product or not for the purpose of higher coefficients, but have not written the code for it as it is practically of no use if the degree of polynomial is large.</p>