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)

use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    let limit = 1000001;
    let sieve = make_sieve(limit);
    let mut ans = 1;
    for i in 2..n {
        let tmp = prime_factorize_fast(i, &sieve);
        let mut num = 1;
        for (_, &value) in &tmp {
            num *= value + 1;
        }
        ans += num;
    }
    println!("{}", ans);
    
}

use std::collections::HashMap;
use MyEither::{IsPrime, NotPrime, Undecided};

#[derive(Clone, Copy, PartialEq)]
enum MyEither<T> {
    IsPrime,
    NotPrime(T),
    Undecided,
}

fn make_sieve(limit: usize) -> Vec<MyEither<usize>> {
    let mut sieve: Vec<MyEither<usize>> = vec![Undecided; limit + 1];
    let mut num = 2;

    while num <= limit {
        if sieve[num] == Undecided {
            sieve[num] = IsPrime;
            let mut tmp = num * num;
            while tmp <= limit {
                sieve[tmp] = match &sieve[tmp] {
                    Undecided => NotPrime(num),
                    n => *n,
                };
                tmp += num;
            }
        }
        num += 1;
    }
    sieve
}

fn prime_factorize_fast(mut n: usize, sieve: &Vec<MyEither<usize>>) -> HashMap<usize, usize> {
    let mut res = HashMap::new();

    while sieve[n] != IsPrime {
        match &sieve[n] {
            NotPrime(num) => {
                let entry = res.entry(*num).or_insert(0);
                *entry += 1;
                n = n / *num;
            }
            _ => break,
        }
    }
    let entry = res.entry(n).or_insert(0);
    *entry += 1;

    res
}