#include<iostream>
#include<cmath>

int main() 
{
   int t1=-1, t2=-1, t3=-1, t4=-1, N=200000;
   double pi=0.0;

   for(int i=0; i<N; i++) {
      double term = pow(-1, i%2) * 4.0 / (2*i+1);
      pi += term;
      if(i<10) std::cout << i << "\t" << pi << std::endl;
      
      if( fabs(pi-3.14) < 0.01 && t1==-1) t1 = i;
      if( fabs(pi-3.141) < 0.001 && t2==-1) t2 = i;
      if( fabs(pi-3.1415) < 0.0001 && t3==-1) t3 = i;
      if( fabs(pi-3.14159) < 0.00001 && t4==-1) t4 = i;

      if( fabs(pi-3.14159265359) < 0.00000000001) break;
   }


   std::cout << "First term with 3.14 is i = " << t1 << std::endl;
   std::cout << "First term with 3.141 is i = " << t2 << std::endl;
   std::cout << "First term with 3.1415 is i = " << t3 << std::endl;
   std::cout << "First term with 3.14159 is i = " << t4 << std::endl;

   return 0;
}
