LoginSignup
1
1

More than 5 years have passed since last update.

Python で Project Euler #16「べき乗の数字和」

Posted at

Problem 16 「べき乗の数字和」

$2^{15} = 32768$ であり, これの数字和 ( 各桁の和 ) は $3 + 2 + 7 + 6 + 8 = 26$ となる.
同様にして, $2^{1000}$ の数字和を求めよ.

Python
# n = 15
n = 1000
result = sum(map(int, str(2 ** n)))

print result
print result == 1366
結果
1366
True
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1