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 self::mod_int::ModInt;
use std::collections::BinaryHeap;

const MOD: usize = 1e9 as usize + 7;
const INF: i64 = 1 << 60;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();

    let mut seg = vec![];
    for _ in 0..n {
        let l: usize = sc.read();
        let r: usize = sc.read();
        seg.push((l, r));
    }

    seg.sort_by_key(|&(l, r)| r - l + 1);
    seg.reverse();

    let mut seg_tree = range_add_segment_tree::RangeAddSegmentTree::new(m + 1, 0, |a, b| a + b, 0);
    for d in 1..(m + 1) {
        while let Some((l, r)) = seg.pop() {
            if r - l + 1 > d {
                seg.push((l, r));
                break;
            } else {
                seg_tree.add(l, r + 1, 1);
            }
        }

        let mut ans = seg.len();
        let mut cur = 0;
        while cur <= m {
            ans += seg_tree.get(cur, cur + 1);
            cur += d;
        }
        sc.write(ans);
        sc.write("\n");
    }
}
pub mod range_add_segment_tree {

    pub struct RangeAddSegmentTree<T, F> {
        seg: Vec<T>,
        seg_add: Vec<T>,
        num: usize,
        f: F,
        init: T,
    }

    impl<T, F> RangeAddSegmentTree<T, F>
    where
        T: PartialOrd + ::std::ops::Add<Output = T> + ::std::ops::Sub<Output = T> + Copy,
        F: Fn(T, T) -> T,
    {
        pub fn new(n: usize, init: T, f: F, zero: T) -> Self {
            let num = n.next_power_of_two();
            RangeAddSegmentTree {
                seg: vec![init; num * 2],
                seg_add: vec![zero; num * 2],
                num: num,
                init: init,
                f: f,
            }
        }

        /// add to [a, b)
        pub fn add(&mut self, a: usize, b: usize, value: T) {
            let num = self.num;
            self.add_to_range(a, b, value, 0, 0, num);
        }

        fn add_to_range(
            &mut self,
            a: usize,
            b: usize,
            value: T,
            mut k: usize,
            left: usize,
            right: usize,
        ) {
            if b <= left || right <= a {
                return;
            }
            if a <= left && right <= b {
                self.seg_add[k] = self.seg_add[k] + value;
                while k > 0 {
                    k = (k - 1) / 2;
                    self.seg[k] = (self.f)(
                        self.seg[k * 2 + 1] + self.seg_add[k * 2 + 1],
                        self.seg[k * 2 + 2] + self.seg_add[k * 2 + 2],
                    );
                }
            } else {
                self.add_to_range(a, b, value, k * 2 + 1, left, (left + right) / 2);
                self.add_to_range(a, b, value, k * 2 + 2, (left + right) / 2, right);
            }
        }

        pub fn update(&mut self, pos: usize, value: T) {
            let cur = self.get(pos, pos + 1);
            let mut k = pos + self.num - 1;
            let raw = self.seg[k];
            self.seg[k] = raw + value - cur;
            while k > 0 {
                k = (k - 1) / 2;
                self.seg[k] = (self.f)(self.seg[k * 2 + 1], self.seg[k * 2 + 2]);
            }
        }

        pub fn get(&self, a: usize, b: usize) -> T {
            self.get_from_range(a, b, 0, 0, self.num)
        }

        fn get_from_range(&self, a: usize, b: usize, k: usize, left: usize, right: usize) -> T {
            if b <= left || right <= a {
                self.init
            } else if a <= left && right <= b {
                self.seg[k] + self.seg_add[k]
            } else {
                let mid = (left + right) / 2;
                let x = self.get_from_range(a, b, k * 2 + 1, left, mid);
                let y = self.get_from_range(a, b, k * 2 + 2, mid, right);
                (self.f)(x, y) + self.seg_add[k]
            }
        }
    }
}
pub mod mod_int {
    use super::MOD;
    use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

    type Num = usize;

    #[derive(Clone, Copy)]
    pub struct ModInt<T: Copy + Clone>(pub T);

    impl Add<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn add(self, rhs: ModInt<Num>) -> ModInt<Num> {
            self + rhs.0
        }
    }

    impl Add<Num> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn add(self, mut rhs: Num) -> ModInt<Num> {
            if rhs >= MOD {
                rhs %= MOD;
            }
            let mut t = rhs + self.0;
            if t >= MOD {
                t = t - MOD;
            }
            ModInt(t)
        }
    }

    impl Sub<Num> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn sub(self, rhs: Num) -> ModInt<Num> {
            let rhs = if rhs >= MOD { rhs % MOD } else { rhs };
            let value = if self.0 < rhs { self.0 + MOD } else { self.0 };
            ModInt(value - rhs)
        }
    }

    impl Sub<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn sub(self, rhs: ModInt<Num>) -> ModInt<Num> {
            self - rhs.0
        }
    }

    impl AddAssign<Num> for ModInt<Num> {
        fn add_assign(&mut self, other: Num) {
            *self = *self + other;
        }
    }
    impl AddAssign<ModInt<Num>> for ModInt<Num> {
        fn add_assign(&mut self, other: ModInt<Num>) {
            *self = *self + other;
        }
    }

    impl SubAssign<Num> for ModInt<Num> {
        fn sub_assign(&mut self, other: Num) {
            *self = *self - other;
        }
    }

    impl SubAssign<ModInt<Num>> for ModInt<Num> {
        fn sub_assign(&mut self, other: ModInt<Num>) {
            *self = *self - other;
        }
    }

    impl Div<Num> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn div(self, mut rhs: Num) -> ModInt<Num> {
            if rhs >= MOD {
                rhs %= MOD;
            }
            self * ModInt(rhs).pow(MOD - 2)
        }
    }

    impl Div<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn div(self, rhs: ModInt<Num>) -> ModInt<Num> {
            self / rhs.0
        }
    }

    impl DivAssign<Num> for ModInt<Num> {
        fn div_assign(&mut self, rhs: Num) {
            *self = *self / rhs
        }
    }
    impl DivAssign<ModInt<Num>> for ModInt<Num> {
        fn div_assign(&mut self, rhs: ModInt<Num>) {
            *self = *self / rhs
        }
    }

    impl Mul<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;

        fn mul(self, rhs: ModInt<Num>) -> ModInt<Num> {
            self * rhs.0
        }
    }
    impl Mul<Num> for ModInt<Num> {
        type Output = ModInt<Num>;

        fn mul(self, mut rhs: Num) -> ModInt<Num> {
            if rhs >= MOD {
                rhs %= MOD;
            }
            let t = (self.0 * rhs) % MOD;
            ModInt(t)
        }
    }

    impl MulAssign<Num> for ModInt<Num> {
        fn mul_assign(&mut self, rhs: Num) {
            *self = *self * rhs;
        }
    }

    impl MulAssign<ModInt<Num>> for ModInt<Num> {
        fn mul_assign(&mut self, rhs: ModInt<Num>) {
            *self = *self * rhs;
        }
    }

    impl ModInt<Num> {
        pub fn pow(self, e: Num) -> ModInt<Num> {
            let mut result = ModInt(1);
            let mut cur = self;
            let mut e = e;
            while e > 0 {
                if e & 1 == 1 {
                    result *= cur;
                }
                e >>= 1;
                cur *= cur;
            }
            result
        }
    }
}
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}