diff options
author | mjfernez <mjfernez@gmail.com> | 2020-02-03 23:04:10 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2020-02-03 23:04:10 -0500 |
commit | 8e431d287c0e89041506da4c4da57e3e3d657d72 (patch) | |
tree | b6cd296fbdd75d1421fe84a82cf3eec859407dcb /bigfactors2.py | |
parent | e6a7399134b3dc08f9e6e9c9c74e39ac449b8538 (diff) | |
download | Project_Euler_Solutions-8e431d287c0e89041506da4c4da57e3e3d657d72.tar.gz |
cleanup, added c translations for some
Diffstat (limited to 'bigfactors2.py')
-rw-r--r-- | bigfactors2.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/bigfactors2.py b/bigfactors2.py index 41bc13d..9e51502 100644 --- a/bigfactors2.py +++ b/bigfactors2.py @@ -1,32 +1,34 @@ -import PIL, math +import PIL +import math + +# Problem 12 Highly divisible triangular number +# finds the first number with over 500 factors -#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 + 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 +i = 1 +k = 1 j = 0 while(k < 500): - j += i - k=countfactors(j) - print(str(j) + " has " + str(k) + " factors") - i += 1 + j += i + k = countfactors(j) + print(str(j) + " has " + str(k) + " factors") + i += 1 print("Ding! Ding! {} has over 500 factors, wow!".format(j)) |