Problem:
Score : 700 points

Problem Statement

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

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

There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M.
For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0.
Here, assume that it is not allowed to change trains.

Constraints

1 ≦ N ≦ 3 × 10^{5}

1 ≦ M ≦ 10^{5}

1 ≦ l_i ≦ r_i ≦ M

Input

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

N M
l_1 r_1
:
l_{N} r_{N}

Output

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

Sample Input 1

3 3
1 2
2 3
3 3

Sample Output 1

3
2
2

If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind 1, 2 and 3.

If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind 1 and 2.

If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind 2 and 3.

Sample Input 2

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

Sample Output 2

7
6
6
5
4
5
5
3
2

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::{stdin, Read};
use std::str::FromStr;

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut q = vec![(0, 0, 0); n];
    for i in 0..n {
        let a = read::<usize>();
        let b = read::<usize>() + 1;
        // [a,b)に行けば1point
        q[i] = (b - a, a, b);
    }
    q.sort();
    let mut cnt = 0;
    let mut fen = Fenwick::new(m + 10);
    for i in 1..m + 1 {
        while cnt < n {
            let (range, l, r) = q[cnt];
            if range < i {
                fen.add(l, 1);
                fen.add(r, -1);
                cnt += 1;
            } else {
                break;
            }
        }
        let mut j = 0;
        let mut sum: i64 = (n - cnt) as i64;
        while j < m + 10 {
            sum += fen.sum(j + 1);
            j += i;
        }
        println!("{}", sum);
    }


}

#[derive(Debug)]
#[allow(dead_code)]
struct Fenwick {
    dat: Vec<i64>,
    n: usize,
}
#[allow(dead_code)]
impl Fenwick {
    pub fn new(n: usize) -> Fenwick {
        Fenwick {
            dat: vec![0i64; n],
            n: n,
        }
    }
    fn sum(&self, _i: usize) -> i64 {
        let mut i = _i.clone() as i64;
        i -= 1;
        let mut ret: i64 = 0i64;
        while i >= 0 {
            ret += self.dat[i as usize];
            i = (i & (i + 1)) - 1;
        }
        ret
    }
    fn sum_range(&self, _l: usize, _r: usize) -> i64 {
        self.sum(_r) - self.sum(_l)
    }
    fn add(&mut self, _i: usize, x: i64) {
        let mut i = _i.clone();
        while i < self.n {
            self.dat[i] += x;
            i = i | (i + 1)
        }
    }
}

#[allow(dead_code)]
fn read_str() -> Vec<char> {
    let s: String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(
        |_| panic!("Faild to parse {}", s),
    )
}