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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());

        var ans = 1L;

        var sieve = new SieveOfEratosthenes(N);

        for (int n = 2; n <= N - 1; n++)
            ans += sieve.GetFactors(n).RunLengthEncode().Select(x => x.length + 1).Aggregate((s, e) => s * e);

        WriteLine(ans);
    }
}

static class RunLengthEncoderExtensions
{
    public static IEnumerable<(T element, int length)> RunLengthEncode<T>(this IEnumerable<T> collection)
    {
        var isFirst = true;
        var prevElement = default(T);
        var length = 0;

        foreach (var element in collection)
        {
            if (!isFirst && !EqualityComparer<T>.Default.Equals(prevElement, element))
            {
                yield return (prevElement, length);
                length = 0;
            }
            else
                isFirst = false;

            length++;
            prevElement = element;
        }
        if (!isFirst)
            yield return (prevElement, length);
    }

    public static IEnumerable<T> RunLengthDecode<T>(this IEnumerable<(T element, int length)> rle) => rle.SelectMany(t => Enumerable.Repeat(t.element, t.length));
}

class SieveOfEratosthenes
{
    public int MaxN { get; }

    public IEnumerable<int> Primes => primes;
    private readonly List<int> primes = new List<int>();
    private readonly int[] factors;

    public SieveOfEratosthenes(int maxN)
    {
        MaxN = maxN;
        factors = new int[maxN + 1];
        factors[0] = factors[1] = -1;

        for (int i = 2; i <= maxN; i++)
        {
            if (factors[i] != 0)
                continue;

            primes.Add(i);

            for (int j = i; j <= maxN; j += i)
                factors[j] = i;
        }
    }

    public bool IsPrime(int n)
    {
        if (MaxN < n)
            throw new ArgumentException();

        if (n < 2)
            return false;

        return factors[n] == n;
    }

    public IEnumerable<int> GetFactors(int n)
    {
        if (MaxN < n)
            throw new ArgumentException();

        var oppositeFactors = new List<int>();
        while (1 < n)
        {
            oppositeFactors.Add(factors[n]);
            n /= factors[n];
        }

        for (int i = oppositeFactors.Count - 1; i >= 0; i--)
            yield return oppositeFactors[i];
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}