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::{io::{self, prelude::*}, *};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut scan = Scanner::new(stdin.lock());
    let mut w = io::BufWriter::new(stdout.lock());
    
    let mut p = Vec::<i64>::new();
    const N:usize =1e6 as usize + 1;
    let mut isp = vec![false; N];
    
    for i in 2..(N as i64) {
        if !isp[i as usize] {
            p.push(i as i64);
        }
        for x in &p {
            if x * i >= N as i64 {
                break;
            }
            isp[(x * i) as usize] = true;
            if i % x == 0 {
                break;
            }
        }
    }
    // writeln!(w, "ok");
    let mut ans = 0;
    let n = scan.next();
    for i in 1..n {
        let mut t = i;
        let mut s = 1;
        for x in &p {
            if x * x > i {
                break;
            }
            let mut c = 0;
            while t % x == 0 {
                c += 1;
                t /= x;
            }
            s *= c + 1;
        }
        if t > 1 {
            s *= 2;
        }
        ans += s;
    }
    writeln!(w, "{}", ans);
}
 
 
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
}