Problem:
Score : 600 points

Problem Statement

Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.

Constraints

1\leq N\leq 10^9

1 2\leq K\leq 100 (fixed at 21:33 JST)

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of sequences, modulo 10^9+7.

Sample Input 1

3 2

Sample Output 1

5

(1,1), (1,2), (1,3), (2,1), and (3,1) satisfy the condition.

Sample Input 2

10 3

Sample Output 2

147

Sample Input 3

314159265 35

Sample Output 3

457397712

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

use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();
    let k: i64 = input();

    ModInt::set_mod(1000000007);

    let mut s = vec![];
    for i in 1.. {
        if i * i > n {
            break;
        }
        s.push(i);
        s.push(n / i);
    }
    s.sort();
    s.dedup();

    let m = s.len();
    let mut w = vec![1; m];
    for i in 0..m - 1 {
        w[i] = n / s[i] - n / s[i + 1];
    }

    let mut dp = vec![vec![ModInt(0); m]; k as usize + 1];
    dp[0][m - 1] += 1;
    for i in 0..k as usize {
        for j in (0..m - 1).rev() {
            let t = dp[i][j + 1];
            dp[i][j] += t;
        }
        for j in 0..m {
            let nj = s.lower_bound(n / s[j]);
            let t = dp[i][nj] * w[j];
            dp[i + 1][j] += t;
        }
    }

    println!("{}", dp[k as usize].iter().sum::<ModInt>());
}

trait LowerBound<T: Ord> {
    fn lower_bound(&self, x: T) -> usize;
}

impl<T: Ord> LowerBound<T> for [T] {
    fn lower_bound(&self, x: T) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if self[m] >= x {
                r = m as i64;
            } else {
                l = m as i64;
            }
        }
        r as usize
    }
}

static mut MOD: i64 = 0;

#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct ModInt(i64);

impl ModInt {
    fn new(x: i64) -> ModInt {
        let m = ModInt::get_mod();
        ModInt(if x < m { x } else { x % m })
    }

    fn get_mod() -> i64 {
        unsafe { MOD }
    }

    fn set_mod(x: i64) {
        unsafe {
            MOD = x;
        }
    }
}

impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.0.fmt(f)
    }
}

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, other: ModInt) -> ModInt {
        let mut x = self;
        x += other;
        x
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, other: ModInt) -> ModInt {
        let mut x = self;
        x *= other;
        x
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, other: ModInt) -> ModInt {
        let mut x = self;
        x -= other;
        x
    }
}

impl<'a> std::ops::Add<&'a ModInt> for ModInt {
    type Output = ModInt;
    fn add(self, other: &'a ModInt) -> ModInt {
        self + *other
    }
}

impl<'a> std::ops::Mul<&'a ModInt> for ModInt {
    type Output = ModInt;
    fn mul(self, other: &'a ModInt) -> ModInt {
        self * *other
    }
}

impl<'a> std::ops::Sub<&'a ModInt> for ModInt {
    type Output = ModInt;
    fn sub(self, other: &'a ModInt) -> ModInt {
        self - *other
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, other: ModInt) {
        let m = ModInt::get_mod();
        self.0 += other.0;
        if self.0 >= m {
            self.0 -= m;
        }
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, other: ModInt) {
        let m = ModInt::get_mod();
        self.0 *= other.0;
        if self.0 >= m {
            self.0 %= m;
        }
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, other: ModInt) {
        let m = ModInt::get_mod();
        self.0 += m - other.0;
        if self.0 >= m {
            self.0 -= m;
        }
    }
}

impl<T: Into<i64>> std::ops::Add<T> for ModInt {
    type Output = ModInt;
    fn add(self, other: T) -> ModInt {
        self + ModInt::new(other.into())
    }
}

impl<T: Into<i64>> std::ops::Mul<T> for ModInt {
    type Output = ModInt;
    fn mul(self, other: T) -> ModInt {
        self * ModInt::new(other.into())
    }
}

impl<T: Into<i64>> std::ops::Sub<T> for ModInt {
    type Output = ModInt;
    fn sub(self, other: T) -> ModInt {
        self - ModInt::new(other.into())
    }
}

impl<T: Into<i64>> std::ops::AddAssign<T> for ModInt {
    fn add_assign(&mut self, other: T) {
        *self += ModInt::new(other.into());
    }
}

impl<T: Into<i64>> std::ops::MulAssign<T> for ModInt {
    fn mul_assign(&mut self, other: T) {
        *self *= ModInt::new(other.into());
    }
}

impl<T: Into<i64>> std::ops::SubAssign<T> for ModInt {
    fn sub_assign(&mut self, other: T) {
        *self -= ModInt::new(other.into());
    }
}

impl std::iter::Sum for ModInt {
    fn sum<I: Iterator<Item = ModInt>>(iter: I) -> ModInt {
        iter.fold(ModInt(0), std::ops::Add::add)
    }
}

impl std::iter::Product for ModInt {
    fn product<I: Iterator<Item = ModInt>>(iter: I) -> ModInt {
        iter.fold(ModInt(1), std::ops::Mul::mul)
    }
}

impl<'a> std::iter::Sum<&'a ModInt> for ModInt {
    fn sum<I: Iterator<Item = &'a ModInt>>(iter: I) -> ModInt {
        iter.fold(ModInt(0), std::ops::Add::add)
    }
}

impl<'a> std::iter::Product<&'a ModInt> for ModInt {
    fn product<I: Iterator<Item = &'a ModInt>>(iter: I) -> ModInt {
        iter.fold(ModInt(1), std::ops::Mul::mul)
    }
}