summaryrefslogtreecommitdiff
path: root/012.c
blob: c5cc49ebfc296385d762be4df2125cfdaf84007d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <math.h>

int count_divisors(unsigned int triangle)
{
	unsigned int i;
	int count = 2;
	int limit = (int) ceil(sqrt(triangle));
	for(i=2; i<limit; i++)
	{
		if(triangle % i == 0)
		{
			if(triangle / i == i)
				count++;
			else
				count += 2;
		}
	}
	return count;
}

int main()
{
	unsigned int triangle = 0;
	int divisors = 0;
	int count = 1;

	do
	{
		triangle += count++;
		divisors = count_divisors(triangle);
	} while(divisors <= 500);

	printf("%d\n", triangle);

	return 0;
}