Ejemplo n.º 1
0
def solve(nthpow):
    """returns sum of numbers that can be written as sum of the nthpow of
    their digits
    """
    from functools import partial
    from utils import sum_digits
    power = partial(pow, exponent=nthpow)

    return filter(lambda n: n == sum_digits(n, power), xrange(2, upper(nthpow)))
Ejemplo n.º 2
0
def curious_numbers():
    """yields all curious numbers. Upper bound can be found by taking a
    n-digit number, then the max sum of its factorials is n*9!. So we
    want to find the limit on n. This happens when 10**(n-1) > n*9!,
    or when n~=7.
    """
    for curr in range(3, 10**6):
        if curr == sum_digits(curr, math.factorial):
            yield curr
Ejemplo n.º 3
0
def main():

    total = 0

    for num in range(2, 100):
        if num not in {4, 9, 16, 25, 36, 49, 64, 81}:
            root = isqrt(num * (10**2)**99)
            total += sum_digits(root)
    return total
Ejemplo n.º 4
0
def main():

    total = 0

    for num in range(2, 100):
        if num not in {4, 9, 16, 25, 36, 49, 64, 81}:
            root = isqrt(num * (10**2)**99)
            total += sum_digits(root)
    return total
Ejemplo n.º 5
0
def main():

    cnt = 0

    for num_digits in count(2):
        max_num = 10**num_digits
        min_num = max_num // 10

        for digit_sum in range(2, num_digits * 9 + 1):
            num = digit_sum * digit_sum
            p = 2

            while num < max_num:
                if min_num <= num < max_num and num == sum_digits(num)**p:
                    cnt += 1
                    if cnt == 30:
                        return num
                num *= digit_sum
                p += 1
Ejemplo n.º 6
0
def main():

    cnt = 0

    for num_digits in count(2):
        max_num = 10**num_digits
        min_num = max_num//10

        for digit_sum in range(2, num_digits*9 + 1):
            num = digit_sum * digit_sum
            p = 2

            while num < max_num:
                if min_num <= num < max_num and num == sum_digits(num)**p:
                    cnt += 1
                    if cnt == 30:
                        return num
                num *= digit_sum
                p += 1
Ejemplo n.º 7
0
 def test_sum_digits(self):
     self.assertEqual(sum_digits(0), 0)
     self.assertEqual(sum_digits(1), 1)
     self.assertEqual(sum_digits(1000), 1)
     self.assertEqual(sum_digits(1234567890), 45)
Ejemplo n.º 8
0
'''
n! means n x (n - 1) x ... x 3 x 2 x 1

Find the sum of the digits in the number 100!
'''
from time import time
from math import factorial
from utils import sum_digits
start=time()

f=factorial(10000)
result=sum_digits(f)

print 'The answer is: '+str(result)
print 'Calculated in '+str(round(time()-start,5))+'s.'
Ejemplo n.º 9
0
'''
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 time import time
from utils import sum_digits
start=time()

result = sum_digits(pow(2,1000))

print 'The answer is: '+str(result)
print 'Calculated in '+str(round(time()-start,5))+'s.'
Ejemplo n.º 10
0
 def test_sum_digits(self):
     self.assertEqual(sum_digits(0), 0)
     self.assertEqual(sum_digits(1), 1)
     self.assertEqual(sum_digits(1000), 1)
     self.assertEqual(sum_digits(1234567890), 45)
Ejemplo n.º 11
0
from utils import factorial, sum_digits

print(sum_digits(factorial(100)))