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())
Why do not you register as a user and use Qiita more conveniently?
  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
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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