Under construction

Still being built. Things may change

Acquainted Through Friends

Time limit0.5sMemory limit1024 MB

Summary
Connect N people into one group where a pair costs their gcd if it is above 1, otherwise the larger number, and find the minimum total cost.
Level

Medium6 of 10

Topics
Number theory, Greedy, Math
Solved
No attempts yet

Problem

The theory that six handshakes are enough to connect everyone in the world is well known. Consider a situation where every person is connected to every other through a chain of acquaintances.

There are NN people who do not know each other. They are numbered from 11 to NN. Any two of them can share a meal and become friends. The price of the meal is set as follows.

  • If the two numbers are coprime, the price is the larger of the two numbers. Two numbers are coprime when their only common divisor is 1.
  • If the two numbers are not coprime, the price is the greatest common divisor of the two numbers.

A friend of a friend, or a friend of a friend of a friend, is called an 'acquaintance through friends'. Draw each friendship as an edge in a graph. If a path exists from vertex uu to vertex vv, then uu and vv are acquainted through friends. If uu and vv are friends, a path exists between them, so they are also acquainted through friends.

The NN people become friends so that every pair is acquainted through friends. Write a program that finds the minimum total price of the meals needed to achieve this.

Input

The input is given as follows.

NN

Output

On the first line, print the minimum total cost.

Constraints

  • 2≤N≤1 000 0002\leq N\leq 1\,000\,000

Examples1

  1. Example 1

    Input
    5
    
    Expected output
    12