Example #1
0
uint p12::execute() 
{
  uint trinum = 0, i = 1, numDivisors = 1;

  while (numDivisors < 500)
  {
    trinum += i++;
    numDivisors = getNumDivisors(trinum);
  }

  return trinum;
}
Example #2
0
void calculateOnSpan(unsigned long int i, unsigned long int triangle, unsigned long int howMany)
{
    unsigned long int start = i;
    bool done = false;
    bool found = false;
    unsigned long int numDivisors;
    while(!done)
    {
        if(i%50 == 0)
        {
            double percent = ((double) (i - start)) / (howMany);
            std::cout << "Start: " << start << " Percent: " << percent << std::endl;
        }

        numDivisors = getNumDivisors(triangle);
        if(numDivisors > 500)
        {
            found = true;
            done = true;
            continue;
        }
        else
        {
            if(i >= start + howMany)
            {
                done = true;
                continue;
            }
            i++;
            triangle += i;
        }
    }

    if(found)
    {
        lockThreads();
        if(triangle < triangle500Divisors)
        {
            foundOne = true;
            triangle500i = i;
            triangle500Divisors = triangle;
            std::cout << "FOUND ONE!   i: " << i << "  tri: " << triangle << "  divs: " << numDivisors << std::endl;
        }
        unlockThreads();
    }
}