aboutsummaryrefslogtreecommitdiffstats
path: root/12-Highly-Divisible-Triangular-Number
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
committermjfernez <mjfernez@gmail.com>2020-02-09 15:16:26 -0500
commit93ea7fe5957b62f18e8fbd17a21696bd7de6332d (patch)
treed90aed60d687bcf195f1150777f37cbe8a149814 /12-Highly-Divisible-Triangular-Number
parent125ec5bc3d8bfc224b7d32bcfbbc37b9fb5d441f (diff)
downloadProject_Euler_Solutions-93ea7fe5957b62f18e8fbd17a21696bd7de6332d.tar.gz
Organized everything, update README
Diffstat (limited to '12-Highly-Divisible-Triangular-Number')
-rwxr-xr-x12-Highly-Divisible-Triangular-Number/bigfactors2bin0 -> 16752 bytes
-rw-r--r--12-Highly-Divisible-Triangular-Number/bigfactors2.c31
-rw-r--r--12-Highly-Divisible-Triangular-Number/bigfactors2.py34
3 files changed, 65 insertions, 0 deletions
diff --git a/12-Highly-Divisible-Triangular-Number/bigfactors2 b/12-Highly-Divisible-Triangular-Number/bigfactors2
new file mode 100755
index 0000000..3e409b1
--- /dev/null
+++ b/12-Highly-Divisible-Triangular-Number/bigfactors2
Binary files differ
diff --git a/12-Highly-Divisible-Triangular-Number/bigfactors2.c b/12-Highly-Divisible-Triangular-Number/bigfactors2.c
new file mode 100644
index 0000000..97ba17d
--- /dev/null
+++ b/12-Highly-Divisible-Triangular-Number/bigfactors2.c
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+int countFactors(int num){
+ int factors = 0;
+ // Check only up until the square root of the number
+ int root = (int) ceil(sqrt(num));
+ //printf("%d\n", root);
+ for(int i = 2; i < root; i++){
+ if(num % i == 0)
+ factors+=2;
+ }
+ // Correction for perfect square
+ if(root * root == num)
+ factors -= 1;
+ return factors;
+}
+
+int main(){
+ int i = 1;
+ int k = 1;
+ int j = 0;
+ while(k < 500){
+ j += i;
+ k = countFactors(j);
+ i += 1;
+ }
+ printf("%d has over 500 factors. Neat!\n", j);
+ return 0;
+}
diff --git a/12-Highly-Divisible-Triangular-Number/bigfactors2.py b/12-Highly-Divisible-Triangular-Number/bigfactors2.py
new file mode 100644
index 0000000..9e51502
--- /dev/null
+++ b/12-Highly-Divisible-Triangular-Number/bigfactors2.py
@@ -0,0 +1,34 @@
+import PIL
+import math
+
+# Problem 12 Highly divisible triangular number
+# finds the first number with over 500 factors
+
+
+def countfactors(num):
+ factors = 0
+ # we only need to know about the FIRST HALF of factors,
+ # one factor implies a second
+ root = int(math.ceil(math.sqrt(num)))
+ divs = range(1, root)
+ for d in divs:
+ if(num % d == 0):
+ factors += 2
+
+ # Correction if the number is a perfect square
+ if (root * root == num):
+ factors -= 1
+ return factors
+
+
+#### MAIN #####
+i = 1
+k = 1
+j = 0
+while(k < 500):
+ j += i
+ k = countfactors(j)
+ print(str(j) + " has " + str(k) + " factors")
+ i += 1
+
+print("Ding! Ding! {} has over 500 factors, wow!".format(j))