Help us understand the problem. What is going on with this article?

Project Euler 45「三角数, 五角数, 六角数」

More than 1 year has passed since last update.

Problem 45 「三角数, 五角数, 六角数」

三角数, 五角数, 六角数は以下のように生成される.

三角数 Tn=n(n+1)/2  1, 3, 6, 10, 15, ...
五角数 Pn=n(3n-1)/2 1, 5, 12, 22, 35, ...
六角数 Hn=n(2n-1)   1, 6, 15, 28, 45, ...

T285 = P165 = H143 = 40755であることが分かる.
次の三角数かつ五角数かつ六角数な数を求めよ.

def hoge():
    n = 143
    while True:
        n += 1
        Hn = n * (2 * n - 1) # 増加幅の大きい六角数を基に
        # 五角数と三角数のチェック
        if (((24 * Hn + 1) ** 0.5 + 1) / 6).is_integer() and \
           (((8 * Hn + 1) ** 0.5 - 1) / 2).is_integer():
            return Hn

print(hoge())
yopya
自然に囲まれた田舎で働きたい。 田舎でPythonの仕事ないっすか?
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