zoukankan      html  css  js  c++  java
  • Problem 56

    Problem 56

    https://projecteuler.net/problem=56

    Powerful digit sum

    A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

    一个古戈尔(10100) 数虽然巨大无比,但是它的位数之和仅仅为1。

    Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

    考虑以下情况:

       aba, b < 100,

      最大的位数之和为多少?

    from power import power
    
    maximum = 0
    for a in range(1, 100):
        for b in range(1, 100):
            num = power(a, b)
            digits = list(str(num))
            digits_sum = 0
            for i in digits:
                digits_sum += int(i)
            if digits_sum > maximum:
                maximum = digits_sum
    print(maximum)
    # power.py
    def power(x, y):
        if y == 1:
            return x
        tot = 1
        for i in range(y):
            tot *= x
        return tot
    
    
    if __name__ == '__main__':
        for x in range(1, 5):
            for y in range(1, 5):
                print('power({0}, {1}) = {2}'.format(x, y, power(x, y)))
    Resistance is Futile!
  • 相关阅读:
    Python的object和type理解及主要对象层次结构
    【译】Matplotlib:plotting
    random
    【译】itertools
    VBA笔记
    Python Function
    Outlook API
    VB参考
    类方法:绑定或无绑定
    【摘录】数据库连接参数
  • 原文地址:https://www.cnblogs.com/noonjuan/p/11060277.html
Copyright © 2011-2022 走看看