結果
| 問題 | No.152 貯金箱の消失 |
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-02-24 19:16:33 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 261 ms / 5,000 ms |
| + 692µs | |
| コード長 | 1,087 bytes |
| 記録 | |
| コンパイル時間 | 54 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 42,752 KB |
| 最終ジャッジ日時 | 2026-09-14 15:26:57 |
| 合計ジャッジ時間 | 2,313 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#!/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 = len(list(gen_pythagorean_triples(N + 1)))
print(answer)
maspy