Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split());S=[[]for _ in range(m+1)];exec("l,r=map(int,input().split());S[r-l+1].append((l, r));"*n);B=[0]*(m+2)
def A(i,a):
 while i<=m+1:B[i]+=a;i+=i&(-i)
def C(i):
 r=0
 while i:r+=B[i];i-=i&(-i)
 return r
for i in range(1,m+1):
 for l,r in S[i]:n-=1;A(l,1);A(r+1,-1)
 r=n
 for j in range(0,m+1,i):r+=C(j)
 print(r)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from itertools import accumulate

class Segtree:
    def __init__(self, original, func, element):
        self.n = len(original)
        self.element = element
        self.func = func
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [element]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = func(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            y = self.seg[i ^ 1]
            i >>= 1
            x = self.func(x, y)
            self.seg[i] = x
                
    def add(self, i, d):
        self.update(i, self.get(i)+d)
        
    def query(self, l, r):
        l += self.N0
        r += self.N0
        nl = self.element
        nr = self.element
        while l < r:
            if l & 1:
                nl = self.func(nl, self.seg[l])
                l += 1
            if r & 1:
                nr = self.func(nr, self.seg[r-1])
            l >>= 1
            r >>= 1
     
        return self.func(nl, nr)

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  A = [0]*(m+2)
  for l, r in LR:
    A[l] += 1
    A[r+1] -= 1
  L = Segtree(A, lambda x, y:x+y, 0)
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  A = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      L.add(l, -1)
      L.add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += L.query(0, j+1)
    A.append(res)
  print(*A[::-1], sep="\n")

if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
class Segtree:
    def __init__(self, original, func, element):
        self.n = len(original)
        self.element = element
        self.func = func
        self.N0 = 1 << (self.n-1).bit_length()
        self.seg = [element]*(self.N0 << 1)
        for i, j in enumerate(original, self.N0):
            self.seg[i] = j
        for i in range(self.N0-1, 0, -1):
            self.seg[i] = func(self.seg[2*i], self.seg[2*i+1])

    def get(self, i):
        return self.seg[i+self.N0]
        
    def update(self, i, x):
        i += self.N0
        self.seg[i] = x
        while i > 1:
            y = self.seg[i ^ 1]
            i >>= 1
            x = self.func(x, y)
            self.seg[i] = x
                
    def add(self, i, d):
        self.update(i, self.get(i)+d)
        
    def query(self, l, r):
        l += self.N0
        r += self.N0
        nl = self.element
        nr = self.element
        while l < r:
            if l & 1:
                nl = self.func(nl, self.seg[l])
                l += 1
            if r & 1:
                nr = self.func(nr, self.seg[r-1])
            l >>= 1
            r >>= 1
     
        return self.func(nl, nr)

n, m = map(int, input().split())
L = Segtree([0]*(m+2), lambda x, y:x+y, 0)
LR = [list(map(int, input().split())) for _ in range(n)]
for l, r in LR:
  L.add(l, 1)
  L.add(r+1, -1)
S = sorted([(r-l+1, l, r) for l, r in LR])
cnt = 0
A = []
for i in range(m, 0, -1):
  while S and S[-1][0] == i:
    c, l, r = S.pop()
    cnt += 1
    L.add(l, -1)
    L.add(r+1, 1)
  res = cnt
  for j in range(0, m+1, i):
    res += L.query(0, j+1)
  A.append(res)
print(*A[::-1], sep="\n")

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

n, m = map(int, input().split())
L = [0]*(m+2)
for i in range(n):
  l, r = map(int, input().split())
  L[l] += 1<<i
  L[r+1] -= 1<<i
A = list(accumulate(L))
for i in range(1, m+1):
  cnt = 0
  for j in range(0, m+1, i):
    cnt |= A[j]
  print(bin(cnt).count("1"))

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

n, m = map(int, input().split())
L = [0]*(m+2)
for i in range(n):
  l, r = map(int, input().split())
  L[l] += 1<<i
  L[r+1] -= 1<<i
A = list(accumulate(L))
for i in range(1, m+1):
  cnt = 0
  for j in range(0, m+1, i):
    cnt |= A[j]
  print(bin(cnt).count("1"))

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  for l, r in LR:
    add(l, 1)
    add(r+1, -1)
  
  S = sorted([(r-l+1, l, r) for l, r in LR])
  cnt = 0
  L = []
  for i in range(m, 0, -1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt += 1
      add(l, -1)
      add(r+1, 1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L[::-1], sep="\n")

if __name__ == "__main__":
  main()