ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

1813. Random Shuffler

Time limit: 0.5 second
Memory limit: 64 MB
Once Sasha decided that a random shuffler in his favourite media player should be replaced. Sasha wants to calculate the order of songs according to the following rule:
x0 = 0,
xi = (xi − 1 · a + b) mod m,
where m is the total number of songs, a and b are integers in range from 0 to m − 1. Generated sequence of song numbers should satisfy the following rules:
  • x0xm − 1 should be a permutation of integers from 0 to m − 1,
  • xm should be equal to zero.
Sasha wants to find all pairs (ai, bi), resulting in a valid sequences and calculate the average among all ai. Help him do it.

Input

The input consists of at most 100 test cases. Each test case is a single line containing an integer m (1 < m < 109).

Output

For each test case output in a single line the average among ai, rounded down.

Sample

inputoutput
2
36
100
123
1
13
41
1
Problem Source: Tavrida NU Akai Contest. Petrozavodsk Summer Session, August 2010.