2017-金马五校程序设计竞赛-I - Frog's Jumping

Description
There are n lotus leaves floating like a ring on the lake, which are numbered 0, 1, …, n-1 respectively. The leaf 0 and n-1 are adjacent.

The frog king wants to play a jumping game. He stands at the leaf 0 initially. For each move, he jumps k (0 < k < n) steps forward. More specifically, if he is standing at the leaf x, the next position will be the leaf (x + k) % n.

After n jumps, he wants to Go through all leaves on the lake and go back to the leaf 0 finally. He can not figure out how many different k can be chosen to finish the game, so he asks you for help.

Input
There are several test cases (no more than 25).
For each test case, there is a single line containing an integer n (3 ≤ n ≤ 1,000,000), denoting the number of lotus leaves.

Output
For each test case, output exactly one line containing an integer denoting the answer of the question above.

Sample Input

4
5

Sample Output

2
4
题目翻译:
一些荷叶漂浮在湖面上其编号是0~n-1,有一只青蛙初始再0位置,它每次可以跳过K个位置(0

代码:

#include
using namespace std;
int fun(int a,int b)
{
    return a%b==0? b:fun(b,a%b);
}
int main()
{
    int n;
    while(cin>>n)
    {
        int ans=0;
        for(int i=1;iif(fun(n,i)==1)
            {
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

你可能感兴趣的:(acm_水题)