Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@yopya

Project Euler 55「Lychrel数」

More than 3 years have passed since last update.

Problem 55 「Lychrel数」

47とその反転を足し合わせると, 47 + 74 = 121となり, 回文数になる.

349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337
349は, 3回の操作を経て回文数になる.

まだ証明はされていないが, 196のようないくつかの数字は回文数にならないと考えられている. 反転したものを足すという操作を経ても回文数にならないものをLychrel数と呼ぶ. 先のような数の理論的な性質により, またこの問題の目的のために, Lychrel数で無いと証明されていない数はLychrel数だと仮定する.

50回未満の操作で回文数になる
まだ誰も回文数まで到達していない

10000未満のLychrel数の個数を答えよ.

``````def hoge(num, limit):
cnt = 0
for n in range(num):
for _ in range(limit):
n += int(str(n)[::-1])
s = str(n)
if s == s[::-1]: break
else:
cnt += 1
return cnt

print(hoge(10000, 50))
``````
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away