diff options
Diffstat (limited to '012.c')
| -rw-r--r-- | 012.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,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; +} + |
