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 std::collections::HashMap;

use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    let mp = min_primes(n);
    let mut result = 0;
    for c in 1..n {
        let ab = n - c;
        let primes = factorization_with_min_primes(ab, &mp);
        let num_of_divisor = primes.values().fold(1, |sum, &x| sum * (x + 1));
        result += num_of_divisor - (ab == 1) as usize;
    }
    println!("{}", result);
}

/// O(n log(log(n))) # calculate vec, which vec[i] mean min(factorization(n))
fn min_primes(size: usize) -> Vec<usize> {
    let mut sieve: Vec<_> = (0..=size).collect();
    for i in 2.. {
        if i * i > size {
            break;
        }
        for j in 2..=(size / i) {
            if sieve[i * j] == i * j {
                sieve[i * j] = i;
            }
        }
    }
    sieve
}

/// O(log(n)) # calculate prime factorization of n, with min_primes
fn factorization_with_min_primes(n: usize, min_primes: &[usize]) -> HashMap<usize, usize> {
    if n <= 1 {
        return vec![(n, 1)].into_iter().collect();
    }
    let (mut divided, mut facts) = (n, HashMap::new());
    while divided > 1 {
        *facts.entry(min_primes[divided]).or_insert(0) += 1;
        divided /= min_primes[divided];
    }
    facts
}