diff options
author | mjfernez <mjfernez@gmail.com> | 2018-12-02 19:12:42 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2018-12-02 19:12:42 -0500 |
commit | d62ba829dc3a54edc46b7deb581dd244713393f5 (patch) | |
tree | 637d985d70fff70c4dedc14a45c559747ea18b84 /bigfactors2.py | |
parent | c15221f10ed2ea4a55b474a57b6ee39f6b24ac85 (diff) | |
download | Project_Euler_Solutions-d62ba829dc3a54edc46b7deb581dd244713393f5.tar.gz |
add code
Diffstat (limited to 'bigfactors2.py')
-rw-r--r-- | bigfactors2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bigfactors2.py b/bigfactors2.py new file mode 100644 index 0000000..5758019 --- /dev/null +++ b/bigfactors2.py @@ -0,0 +1,31 @@ +import PIL, math +import numpy as np + +#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 |