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)))

最新文章

  1. 完美解决全面屏蔽Google教程(终结者)
  2. SOA 架构中的ESB是更好的应用于异构系统集成整合还是用于统一服务调用/基础服务实施
  3. ubuntu 安装fcitx输入法
  4. 从Jetty、Tomcat和Mina中提炼NIO构架网络服务器的经典模式(一)
  5. C#并行和多线程编程_(1)认识Parallel
  6. CSS左侧固定宽 右侧自适应(兼容所有浏览器)
  7. springBoot系列教程05:fastjson的集成、配置及使用
  8. IE浏览器getElementsByTagName方法的兼容问题
  9. erlang二进制
  10. centos修改主机名 root@后面的名字
  11. ul li 的 float:left;
  12. Codeforces Round#416 Div.2
  13. iOS: Designated Initializer(指定初始化函数)
  14. 【已解决】mac上appium报错:“Could not find aapt Please set the ANDROID_HOME environment variable with the Android SDK root directory path”
  15. 020.Zabbix的Actions配置
  16. ExecutorService中submit和execute的区别&lt;转&gt;
  17. C#怎样用文件读写在文件的原有基础上追加一行数据
  18. AtCoder Grand Contest 019 F-yes or no
  19. 深入理解javascript函数系列第三篇
  20. 说说JDK中的List-ArrayList、Vector、LinkedList

热门文章

  1. vijos - P1302连续自然数和 (公式推导 + python)
  2. pygame save that Stream as video output.
  3. springmvc的执行流程详解
  4. JavaScript Patterns 2.5 (Not) Augmenting Build-in Prototypes
  5. 选择排序(1)——简单选择排序(selection sort)
  6. [POI 2018] Prawnicy
  7. MySQL 字符编码问题详细解释
  8. Coursera Algorithms week3 快速排序 练习测验: Decimal dominants(寻找出现次数大于n/10的元素)
  9. Hyper-v 3.0 安装centos6.3
  10. 解决macOS升级之后每次使用ssh都要输入密码的问题