コード例 #1
0
ファイル: 020.py プロジェクト: ametisf/projecteuler
#!/usr/bin/python3

"""
Problem 20 - Factorial digit sum

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!
"""

from modules.matlib import factorial, digitalSum

print(digitalSum(factorial(100))) # output digital sum of 100!
コード例 #2
0
ファイル: 016.py プロジェクト: ametisf/projecteuler
#!/usr/bin/python3

"""
Problem 16 - Power digit sum

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?
"""

from modules.matlib import digitalSum

print(digitalSum(2**1000)) # output digital sum of 2^1000
コード例 #3
0
ファイル: 080.py プロジェクト: ametisf/projecteuler
#!/usr/bin/python3

"""
Problem 80 - Square root digital expansion

It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.

The square root of two is 1.41421356237309504880..., and the digital sum of the first one hundred decimal digits is 475.

For the first one hundred natural numbers, find the total of the digital sums of the first one hundred decimal digits for all the irrational square roots.
"""

from math import sqrt
from modules.matlib import sqrtDecimalExpansion, digitalSum

sm = 0 # sum
for x in range(1, 100): # first 99 natural numbers (100 is square)
    if sqrt(x) % 1 != 0: # if number is not square
        sm += digitalSum(sqrtDecimalExpansion(x, 100)) # add digital sum of it's decimal expansion

print(sm) # output result