E - Snuke Line Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700700

問題文

すぬけくんは鉄道会社を運営するゲームで遊ぶことにしました。すぬけ鉄道には M+1M+1 個の駅があり、 00 から MM までの番号がついています。 すぬけ鉄道の列車は駅 00 から dd 駅ごとに停車します。 例えば d=3d = 3 のとき駅 00,駅 33,駅 66,駅 99, ...... に停車します。

すぬけ鉄道が走っている地域には NN 種類の名産品があり、種類 ii の名産品は 駅 lil_i,駅 li+1l_i+1,駅 li+2l_i+2, ......, 駅 rir_i のいずれかに列車が停車したとき購入することが可能です。

列車が停車する間隔 dd1,2,3,...,M1, 2, 3, ..., MMM 種類が存在しています。 MM 種類の列車それぞれについて、その列車に駅 00 で乗車した場合に購入可能な名産品の種類数を求めなさい。 なお、列車から別の列車への乗り換えは許されないものとします。

制約

  • 1N3×1051 ≦ N ≦ 3 × 10^{5}
  • 1M1051 ≦ M ≦ 10^{5}
  • 1liriM1 ≦ l_i ≦ r_i ≦ M

入力

入力は以下の形式で標準入力から与えられる。

NN MM
l1l_1 r1r_1
::
lNl_{N} rNr_{N}

出力

答えを MM 行に出力せよ。 ii 行目では ii 駅ごとに停車する列車に乗った場合に購入可能な名産品の種類数を出力せよ。


入力例 1Copy

Copy
3 3
1 2
2 3
3 3

出力例 1Copy

Copy
3
2
2
  • 11 駅ごとに停車する列車に乗った場合、種類 1,2,31,2,333 種類の名産品を購入することが可能です。
  • 22 駅ごとに停車する列車に乗った場合、種類 1,21,222 種類の名産品を購入することが可能です。
  • 33 駅ごとに停車する列車に乗った場合、種類 2,32,322 種類の名産品を購入することが可能です。

入力例 2Copy

Copy
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4

出力例 2Copy

Copy
7
6
6
5
4
5
5
3
2

Score : 700700 points

Problem Statement

Snuke has decided to play a game, where the player runs a railway company. There are M+1M+1 stations on Snuke Line, numbered 00 through MM. A train on Snuke Line stops at station 00 and every dd-th station thereafter, where dd is a predetermined constant for each train. For example, if d=3d = 3, the train stops at station 00, 33, 66, 99, and so forth.

There are NN kinds of souvenirs sold in areas around Snuke Line. The ii-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations lil_i, li+1l_i+1, li+2l_i+2, ......, rir_i.

There are MM values of dd, the interval between two stops, for trains on Snuke Line: 11, 22, 33, ......, MM. For each of these MM values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of dd at station 00. Here, assume that it is not allowed to change trains.

Constraints

  • 1N3×1051 ≦ N ≦ 3 × 10^{5}
  • 1M1051 ≦ M ≦ 10^{5}
  • 1liriM1 ≦ l_i ≦ r_i ≦ M

Input

The input is given from Standard Input in the following format:

NN MM
l1l_1 r1r_1
::
lNl_{N} rNr_{N}

Output

Print the answer in MM lines. The ii-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every ii-th station.


Sample Input 1Copy

Copy
3 3
1 2
2 3
3 3

Sample Output 1Copy

Copy
3
2
2
  • If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind 11, 22 and 33.
  • If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind 11 and 22.
  • If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind 22 and 33.

Sample Input 2Copy

Copy
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4

Sample Output 2Copy

Copy
7
6
6
5
4
5
5
3
2


2025-04-22 (Tue)
10:27:12 +00:00