結果
問題 |
No.152 貯金箱の消失
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:19:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,306 ms / 5,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 76,248 KB |
最終ジャッジ日時 | 2025-06-12 14:19:46 |
合計ジャッジ時間 | 5,292 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
def count_magic_squares(L): mod = 1000003 max_sum = L // 4 if max_sum < 3: return 0 count = 0 m_max = int((max_sum / 2) ** 0.5) for m in range(2, m_max + 1): for n in range(1, m): if (m - n) % 2 == 0: continue # both odd if (m % 2 == 1) and (n % 2 == 1): continue # both odd if (m % 2 == 0) and (n % 2 == 0): continue # both even, not coprime if (m % 2 == 0) and (n % 2 == 1): pass if (m % 2 == 1) and (n % 2 == 0): pass if (m % 2 == 0) and (n % 2 == 0): continue # not coprime, same parity if (m % 2 == 1) and (n % 2 == 1): continue # both odd if (m % 2 == 0) and (n % 2 == 0): continue # both even, not coprime # Check if coprime gcd_mn = 1 for d in range(2, min(m, n) + 1): if m % d == 0 and n % d == 0: gcd_mn = d break if gcd_mn != 1: continue # Now, compute s s = 2 * m * (m + n) if s > max_sum: continue count += 1 return count % mod # Read input L = int(input()) # Compute and print the result print(count_magic_squares(L))