summaryrefslogtreecommitdiff
path: root/012.c
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:21:45 +0200
committerReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:35:09 +0200
commit95341b61b030c9e1290f3b326cb7ec584f543aea (patch)
tree852386fa04d32eb859bca11c0eff7b5ef9e50f00 /012.c
parent571164d977f91925c4c76a292f74f5f93d09ae23 (diff)
moved files to higher directory after split to new repositoryHEADtrunk
Diffstat (limited to '012.c')
-rw-r--r--012.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/012.c b/012.c
new file mode 100644
index 0000000..c5cc49e
--- /dev/null
+++ b/012.c
@@ -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;
+}
+