結果

問題 No.152 貯金箱の消失
ユーザー gew1fw
提出日時 2025-06-12 19:22:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 816 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 76,436 KB
最終ジャッジ日時 2025-06-12 19:22:55
合計ジャッジ時間 1,668 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def count_shapes(L):
    mod = 1000003
    if L < 4:
        return 0
    max_total = L // 4  # 因为4*(a + b + c) <= L
    count = 0
    max_m = int(math.sqrt(max_total // 2)) + 1  # 因为 a + b + c = 2m(m + n)
    for m in range(2, max_m + 1):
        for n in range(1, m):
            if math.gcd(m, n) != 1:
                continue
            if (m % 2 == 0 and n % 2 == 0) or (m % 2 != 0 and n % 2 != 0):
                continue
            a = m*m - n*n
            b = 2 * m * n
            if a > b:
                a, b = b, a
            c = m*m + n*n
            total = 4 * (a + b + c)
            if total <= L:
                count += 1
    return count % mod

def main():
    L = int(sys.stdin.readline())
    print(count_shapes(L))

if __name__ == "__main__":
    main()
0