結果
| 問題 |
No.407 鴨等素数間隔列の数え上げ
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-07-10 22:26:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 1,000 ms |
| コード長 | 892 bytes |
| コンパイル時間 | 330 ms |
| コンパイル使用メモリ | 82,532 KB |
| 実行使用メモリ | 88,572 KB |
| 最終ジャッジ日時 | 2024-12-15 14:55:45 |
| 合計ジャッジ時間 | 3,757 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 |
ソースコード
#!/usr/bin/env pypy3
# 制約再々変更後の想定解 (L <= 10 ^ 7)
import array
MIN_N = 3
MAX_N = 10 ** 6
MIN_L = 1
MAX_L = 10 ** 7
def sieve_of_eratosthenes(end, typecode="L"):
assert end > 1
is_prime = array.array("B", (True for i in range(end)))
is_prime[0] = False
is_prime[1] = False
primes = array.array(typecode)
for i in range(2, end):
if is_prime[i]:
primes.append(i)
for j in range(2 * i, end, i):
is_prime[j] = False
return primes
def count_sequences(n, l):
d_max = l // (n - 1)
if d_max < 2:
return 0
ds = sieve_of_eratosthenes(d_max + 1)
return sum(l - (n - 1) * d + 1 for d in ds)
def main():
n, l = map(int, input().split())
assert MIN_N <= n <= MAX_N
assert MIN_L <= l <= MAX_L
print(count_sequences(n, l))
if __name__ == '__main__':
main()
はむ吉🐹