CodeForces 55A. Flea travel

Description

A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.

Input

The only line contains single integer: 1 ≤ n ≤ 1000 — number of hassocks.

Output

Output "YES" if all the hassocks will be visited and "NO" otherwise.

Sample Input

Input
1
Output
YES
Input
3
Output
NO



找规律啦。

#include <iostream>
#include <cstdio>
using namespace std;
int a[1000];
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        int i,sum=0;
        for(i=1; i<=n; i++)
        {
            sum+=i;
        }
        a[0]=1;
        a[1]=2;
        for(i=2; i<n; i++)
        {
            a[i]=(a[i-1]+(i-1))%n+1;

        }
        int sum1=0;
        for(i=0; i<n; i++)
        {
            sum1+=a[i];
        }

        if(sum==sum1)

            cout<<"YES"<<endl;

        else
            cout<<"NO"<<endl;
    }
    return 0;
}


你可能感兴趣的:(CodeForces 55A. Flea travel)