This page is still under construction.

Parts of this page are still being built. What you see may change.

Wiring

Time limit1sMemory limit256 MB

Summary
Count how many distinct wires appear after N squared triangular steps join nails around a circle.
Level

Medium7 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

There are NN nails driven into the rim of a large circle at equal spacing. Call one of them P0P_0, then name the rest P1P_1 through PN−1P_{N-1} going clockwise.

Wires are connected by the following rule.

  1. Let Q0=P0Q_0 = P_0.
  2. Repeat step pp from step 11 to step N2N^2. If Qp−1=PkQ_{p-1} = P_k, set Qp=P(k+p) mod NQ_p = P_{(k+p) \bmod N} and join Qp−1Q_{p-1} to QpQ_p with a wire. If the two nails are already joined, no new wire is added. If Qp−1Q_{p-1} and QpQ_p are the same nail, no wire is added.

Find how many wires are connected once every step is done.

Input

The first line contains a natural number NN. (3≤N≤10123 \le N \le 10^{12})

Output

Print the number of connected wires on the first line.

Examples3

  1. Example 1

    Input
    3
    
    Expected output
    1
    
  2. Example 2

    Input
    4
    
    Expected output
    3
    
  3. Example 3

    Input
    5
    
    Expected output
    2