結果

問題 No.152 貯金箱の消失
ユーザー maspymaspy
提出日時 2020-02-24 19:14:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 395 ms / 5,000 ms
コード長 1,092 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 13:30:35
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,624 KB
testcase_01 AC 28 ms
10,624 KB
testcase_02 AC 27 ms
10,624 KB
testcase_03 AC 27 ms
10,624 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 35 ms
10,880 KB
testcase_07 AC 84 ms
10,880 KB
testcase_08 AC 391 ms
10,880 KB
testcase_09 AC 395 ms
11,008 KB
testcase_10 AC 328 ms
10,880 KB
testcase_11 AC 205 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
# import numpy as np
# from numba import njit

# %%
def gen_pythagorean_triples(bound):
    """generate primitive pythagorean triples.


    Parameters
    ----------
    bound : int
        upper bound of pelimeter of the triangle

    Yields
    -------
    tuple(int, int, int)
        primitive pythagorean triangles
    """
    if bound <= 12:
        return
    yield (3, 4, 5)
    stack = [(3, 4, 5)]
    while stack:
        a, b, c = stack.pop()
        for x, y, z in [
                (a - 2 * b + 2 * c, 2 * a - b + 2 * c, 2 * a - 2 * b + 3 * c),
                (a + 2 * b + 2 * c, 2 * a + b + 2 * c, 2 * a + 2 * b + 3 * c),
                (-a + 2 * b + 2 * c, -2 * a + b + 2 * c, -2 * a + 2 * b + 3 * c)]:
            if x + y + z < bound:
                yield (x, y, z)
                stack.append((x, y, z))


# %%
L = int(readline())

# %%
N = L // 4
answer = sum(1 for x in gen_pythagorean_triples(N + 1))
print(answer)
0