Cogman
Lifer
http://www.projecteuler.net
I'm sure we all know about this.. however, I thought it would be fun to discuss what solutions we come up with here.
I'm currently working on #12
I have a general brute force solution, but not the actual fast solution. The big slowdown is in the getNumDivisors function. I'm not sure how to speed it up (I have an idea with using primes, but am not sure if it is the correct one.)
I'm sure we all know about this.. however, I thought it would be fun to discuss what solutions we come up with here.
I'm currently working on #12
Code:
#include <iostream>
#include <vector>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;
int getNumDivisors(long long val)
{
int numDivisors = 0;
for (int i = 2; i <= val; ++i)
{
if (val % i == 0)
{
++numDivisors;
}
}
return numDivisors;
}
long long triNum(long long n)
{
return ((n * n + n) >> 1);
}
int main()
{
int i = 1;
int numDiv;
numDiv = getNumDivisors(triNum(i));
while (numDiv <= 500)
{
i += 1;
numDiv = getNumDivisors(triNum(i));
}
cout << i << endl;
}
I have a general brute force solution, but not the actual fast solution. The big slowdown is in the getNumDivisors function. I'm not sure how to speed it up (I have an idea with using primes, but am not sure if it is the correct one.)