$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
More than 5 years have passed since last update.
$2^{15} = 32768$ であり, これの数字和 ( 各桁の和 ) は $3 + 2 + 7 + 6 + 8 = 26$ となる.
同様にして, $2^{1000}$ の数字和を求めよ.
# n = 15
n = 1000
result = sum(map(int, str(2 ** n)))
print result
print result == 1366
1366
True
Register as a new user and use Qiita more conveniently