結果
問題 |
No.781 円周上の格子点の数え上げ
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:59:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,961 ms / 2,000 ms |
コード長 | 1,392 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 81,568 KB |
実行使用メモリ | 154,256 KB |
最終ジャッジ日時 | 2025-04-16 16:02:09 |
合計ジャッジ時間 | 7,382 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import sys def sieve(max_n): spf = list(range(max_n + 1)) for i in range(2, int(max_n**0.5) + 1): if spf[i] == i: # i is a prime for j in range(i * i, max_n + 1, i): if spf[j] == j: spf[j] = i return spf def main(): X, Y = map(int, sys.stdin.readline().split()) if X == 0: X = 1 # Since X >= 1 per problem constraints max_n = Y spf = sieve(max_n) max_f = 0 for R in range(X, Y + 1): current = R product = 1 valid = True while current > 1: p = spf[current] if p % 4 == 3: cnt = 0 while current % p == 0: cnt += 1 current = current // p if cnt % 2 != 0: valid = False break elif p == 2: # Remove all factors of 2 while current % p == 0: current = current // p else: # p % 4 == 1 cnt = 0 while current % p == 0: cnt += 1 current = current // p product *= (cnt + 1) if valid: current_f = 4 * product if current_f > max_f: max_f = current_f print(max_f) if __name__ == '__main__': main()