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 Java (OpenJDK 11.0.6) (judge verdict: Time Limit Exceeded)

import java.util.*;
import java.io.*; 
class Main { 

	static void SieveOfEratosthenes(int n, boolean prime[],int a[]) 
	{ 
		
		for (int i = 2; i <= n; i++) 
			prime[i] = true; 

		
		prime[1] = false; 

		for (int p = 2; p * p <= n; p++) { 
			
			if (prime[p] == true) { 
			
				for (int i = p * 2; i <= n; i += p) 
					prime[i] = false; 
			} 
		} 

		int j = 0; 
		for (int p = 2; p <= n; p++) { 
			if (prime[p]) { 
			
				a[j] = p; 

			
				j++; 
			} 
		} 
	} 
	static int countDivisors(int n) 
	{ 	
		if (n == 1) 
			return 1; 
		boolean prime[] = new boolean[n + 1]; 
		int a[] = new int[n]; 
		SieveOfEratosthenes(n, prime,a); 
		int ans = 1; 
		for (int i = 0;; i++) { 
			if (a[i] * a[i] * a[i] > n) 
				break; 
			int cnt = 1; 
			while (n % a[i] == 0) { 
				n = n / a[i]; 
				cnt = cnt + 1; 
			} 
			ans = ans * cnt; 
		} 
		if (prime[n]) 
			ans = ans * 2;
		else if (isPerfect(n) && prime[(int)Math.sqrt(n)]) 
			ans = ans * 3; 
		else if (n != 1) 
			ans = ans * 4; 
		return ans; 
	} 

	
	public static void main(String args[]) 
	{ 
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum=0;
		int x=0;
		int m=0;
		for(int i=1;i<=n-1;i++){
			m = n-i;
			if(m!=1){
				x = countDivisors(m);
				sum+=x;
			}
			else if(m==1){
				sum+=1;
			}
		}
		System.out.println(sum); 
	} 
	public static boolean isPerfect(int n){
		if(Math.sqrt(n)==Math.floor(Math.sqrt(n))){
			return true;
		}
		return false;
	}
}