Problem:
Score : 300 points

Problem Statement

Given is a positive integer N.
How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?

Constraints

2 \leq N \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

3

Sample Output 1

3

There are 3 tuples of integers that satisfy A \times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).

Sample Input 2

100

Sample Output 2

473

Sample Input 3

1000000

Sample Output 3

13969985

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

fn solve() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let spf = smaller_prime_factors(n);
    let factor = move |x: usize| {
        let mut x = x;
        let mut ret = std::collections::HashMap::new();
        while x != 1 {
            *ret.entry(spf[x]).or_insert(0) += 1;
            x /= spf[x];
        }
        ret
    };

    let mut ans = 1;
    for i in 2..n {
        let m = factor(i);
        let mut t: i64 = 1;
        for &v in m.values() {
            t *= v + 1;
        }
        ans += t;
    }

    println!("{}", ans);
}

fn smaller_prime_factors(n: usize) -> Vec<usize> {
    let mut spf: Vec<usize> = (0..(n + 1)).collect();

    for i in 2 as usize..(n + 1) {
        if spf[i] == i {
            for j in ((i * i)..(n + 1)).step_by(i as usize) {
                if spf[j] == j {
                    spf[j] = i;
                }
            }
        }
    }
    spf
}

fn main() {
    solve();
}