結果

問題 No.3101 Range Eratosthenes Query
ユーザー sasa8uyauya
提出日時 2025-04-12 00:06:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 386,380 KB
最終ジャッジ日時 2025-04-12 00:06:19
合計ジャッジ時間 9,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1 -- * 1
other -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

class FenwickTree:
  def __init__(self, size):
    self.n = size
    self.tree = [0] * (self.n + 1)
  
  def add(self, index, delta):
    index += 1
    while index <= self.n:
      self.tree[index] += delta
      index += index & -index
  
  def sum(self, index):
    index += 1
    res = 0
    while index > 0:
      res += self.tree[index]
      index -= index & -index
    return res


L=10**6
f=[[] for i in range(L+1)]
for i in range(1,L+1):
  for j in range(i,L+1,i):
    f[j]+=[i]
  f[i]=f[i][-2:]

q=[]
for i in range(2,L+1):
  p2,p1=f[i]
  q+=[(p2+1,0,p1,1),(p1+1,0,p1,-1)]

Q=int(input())
ans=[0]*Q
for i in range(Q):
  l,r=map(int,input().split())
  if l==1:
    ans[i]=1
  else:
    q+=[(l,1,r,i)]

q.sort()
st=FenwickTree(L+2)
for _,f,r,v in q:
  if f:
    ans[v]=st.sum(r)
  else:
    st.add(r,v)

print(*ans,sep="\n")
0