dimanche 28 juin 2015

Project Euler #29. What is wrong in my method?

int main()
{
    vector <float> a;
    int count=0;
    float k;
    int size=100;
    count=(size-1)*(size-1);

// take the log of all the values and put them in an array

    for(int i=2;i<=size;i++)
        for(int j=2;j<=size;j++)
            a.push_back(k=i*log(j));

// sort the vector array

    sort(a.begin(),a.begin()+count);
    int distinct=count;

//check for duplicates, for each duplicate reduce 1 from total no. of elements

    for(int i=0;i<count;i++)
        if(a[i]==a[i+1])
            distinct--;

// Output distinct

    cout<<distinct<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire