aboutsummaryrefslogtreecommitdiffstats
path: root/bigfactors2.c
diff options
context:
space:
mode:
authormjfernez <mjfernez@gmail.com>2020-02-03 23:04:10 -0500
committermjfernez <mjfernez@gmail.com>2020-02-03 23:04:10 -0500
commit8e431d287c0e89041506da4c4da57e3e3d657d72 (patch)
treeb6cd296fbdd75d1421fe84a82cf3eec859407dcb /bigfactors2.c
parente6a7399134b3dc08f9e6e9c9c74e39ac449b8538 (diff)
downloadProject_Euler_Solutions-8e431d287c0e89041506da4c4da57e3e3d657d72.tar.gz
cleanup, added c translations for some
Diffstat (limited to 'bigfactors2.c')
-rw-r--r--bigfactors2.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/bigfactors2.c b/bigfactors2.c
new file mode 100644
index 0000000..97ba17d
--- /dev/null
+++ b/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;
+}