示例#1
0
Problem:
    Find the sum of digits in the numerator of the 100th convergent of the
    continued fraction for e.

Performance time: ~0.0012s

"""

from fractions import Fraction
from timer import timer
from utils import sum_of_digits


timer.start()

a = [int(n / 3 * 2) if n % 3 == 0 else 1 for n in range(1, 101)]
a[0] = 2

def convergent_e(limit=-1, index=0):
    if limit == 0:
        return a[0]
    elif index == limit - 1:
        return a[index] + Fraction(1, a[index+1])
    else:
        return a[index] + Fraction(1, convergent_e(limit, index+1))

print(sum_of_digits(Fraction(convergent_e(99)).numerator))

timer.stop()
示例#2
0
def main():
    print "\n\n___ Задание 5: Псевдосумма " + "_"*15

    digit = 456
    result = sum_of_digits(digit)
    print digit, ">>", result
示例#3
0
"""

Problem :
    Find the sum of the digits in the number 100!

Performance time: ~0.00005s

"""

from utils import sum_of_digits
from math import factorial
from timer import timer

timer.start()
print(sum_of_digits(factorial(100)))
timer.stop()
示例#4
0
from math import factorial
from utils import sum_of_digits

print(sum_of_digits(factorial(100)))
示例#5
0
from utils import sum_of_digits

print(sum_of_digits(2**1000))
示例#6
0
def main():
    print "\n\n___ Задание 5: Псевдосумма " + "_" * 15

    digit = 456
    result = sum_of_digits(digit)
    print digit, ">>", result
示例#7
0
"""

Problem :
    What is the sum of the digits of the number 2^1000?

Performance time: ~0.00010s

"""

from utils import sum_of_digits
from timer import timer

timer.start()
print(sum_of_digits(2**1000))
timer.stop()
示例#8
0
Problem:
    Find the sum of digits in the numerator of the 100th convergent of the
    continued fraction for e.

Performance time: ~0.0012s

"""

from fractions import Fraction
from timer import timer
from utils import sum_of_digits

timer.start()

a = [int(n / 3 * 2) if n % 3 == 0 else 1 for n in range(1, 101)]
a[0] = 2


def convergent_e(limit=-1, index=0):
    if limit == 0:
        return a[0]
    elif index == limit - 1:
        return a[index] + Fraction(1, a[index + 1])
    else:
        return a[index] + Fraction(1, convergent_e(limit, index + 1))


print(sum_of_digits(Fraction(convergent_e(99)).numerator))

timer.stop()