//evaluate the shekel5 function at 1.0E+8 points
//and record the time
#include <iostream>
#include <ctime>
using namespace std;

int main()
{
    clock_t clock_start, clock_end;
    double dif;
    int i,j;
    double a[4][5]=
    //initialization of array a
    {
      {4.,1.,8.,6.,3.},
      {4.,1.,8.,6.,7.},
      {4.,1.,8.,6.,3.},
      {4.,1.,8.,6.,7.}
    };
    double c[5]=
    {0.1,0.2,0.2,0.4,0.4};
    double S,fmin, w;
    int i0,i1,i2,i3;
    double x[4];
    clock_start = clock();
    //start time
    for (i0=1; i0<100; i0++)
    {
       x[0]=i0;
       for (i1=1; i1<100; i1++)
       {
          x[1]=i1;
          for (i2=1; i2<100; i2++)
          {
              x[2]=i2;
              for (i3=1; i3<100; i3++)
              {
                 x[3]=i3;
                 S = 0;
                 for (i=0; i<5; i++)
                 {
                    w=c[i];
                    for (j=0; j<4; j++)
                       w = w + (x[j]-a[i][j])*(x[j]-a[i][j]);
                    S = S + 1/w;
                 }
                    S = -S;
                    fmin = S;
               }
           }
        }
      }
    //end time
    clock_end = clock();
    //time of calculation
    dif = (clock_end - clock_start+0.)/CLOCKS_PER_SEC;
    cout << "Time for 1.0E+8 points is "<<dif<<" seconds\n";
    return 0;
}

