Project Euler56 をpythonで解く
問題
A googol (10^100) is a massive number: one followed by one-hundred zeros; 100^100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
Considering natural numbers of the form, ab, where a, b 100, what is the maximum digital sum?
10の10乗や100の100乗はその値自体は巨大であるが、各桁の数字の合計は1である。
a^b(1<a,b<100)の各桁の数字の合計の最大値を求めよ。
特に言うことがないので解答です。
解答
max_sum=(0)
for a in range(1,100):
for b in range(1,100):
sum=0
for i in str(a**b):
sum +=int(i)
if sum>max_sum:
max_sum=(sum)
print(max_sum)
グローバル変数とローカル変数の違いにさえ気をつければなんということはないです。
答えは972(a=99,b=95)でした。