#P15527. [ROIR 2015 Day 2] circle 环形线路

[ROIR 2015 Day 2] circle 环形线路

Problem Description

In the city where Andrei and Boris live, the metro consists of a single circular line. Along this line, nn stations are placed at equal distances and are numbered from 11 to nn. The segment between two neighboring stations is called an interval.

Trains on the circular line can travel clockwise or counterclockwise. Therefore, to get from one station to another, a passenger can choose the direction that passes through fewer intervals. The minimum number of intervals needed to travel from one station to another is called the distance between the two stations.

The friends noticed the following property: if we fix a station XX and write down two numbers, DaD_a — the distance from Andrei’s home station to station XX, and DbD_b — the distance from Boris’s home station to station XX, then the obtained pair [Da,Db][D_a, D_b] uniquely determines station XX.

For example, if n=4n = 4, Andrei lives at station 11, and Boris lives at station 22, then station 11 is represented by [0,1][0, 1], station 22 by [1,0][1, 0], station 33 by [2,1][2, 1], and station 44 by [1,2][1, 2].

Their classmate Sergey lives in a nearby city and does not know which stations Andrei and Boris live at. To find his friends, he is interested in how many ordered pairs of stations A,BA, B there are such that, if Andrei lives at station AA and Boris lives at station BB, the property above holds.

Task: Write a program that, given the number of stations nn on the circular line, determines the number of station pairs that satisfy the property.

Input Format

The first line of the input file contains one integer nn (3≤n≤40,0003 \leq n \leq 40,000).

Output Format

The output file should contain one integer — the number of station pairs found.

4
8
5
20

Hint

Example explanation

In the first example, the station pairs that satisfy the property are:

  • Andrei lives at station 11, Boris lives at station 22;
  • Andrei lives at station 11, Boris lives at station 44;
  • Andrei lives at station 22, Boris lives at station 11;
  • Andrei lives at station 22, Boris lives at station 33;
  • Andrei lives at station 33, Boris lives at station 22;
  • Andrei lives at station 33, Boris lives at station 44;
  • Andrei lives at station 44, Boris lives at station 11;
  • Andrei lives at station 44, Boris lives at station 33.

Scoring system and subtasks

Subtask 1 (25 points)

3≤n≤503 \leq n \leq 50.

Subtask 2 (25 points)

3≤n≤5003 \leq n \leq 500.

Subtask 3 (50 points)

3≤n≤40,0003 \leq n \leq 40,000.

Translation source: GPT 5.2.

Translated by ChatGPT 5