Codeforces Beta Round #51 A. Flea travel 水题

A. Flea travel

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/55/problem/A

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

1

Sample Output

YES

HINT

 

题意

有一个环,有n个位置

一开始你在0,然后往前跳,第一次跳n-1,第二次跳n-2,第三次跳n-3.....直到跳到不能跳为止

问你是否能够遍历所有的位置

题解:

数据范围只有1000,直接暴力就好了

代码:

#include<iostream>
#include<stdio.h>
using namespace std;

int p[1005];
int main()
{
    int n;scanf("%d",&n);
    p[0]=1;
    int ans = 1;
    int tmp = 0;
    for(int i=n-1;i>0;i--)
    {
        tmp = (tmp + i)%n;
        if(p[tmp]==0)
        {
            p[tmp]=1;
            ans++;
        }
    }
    if(ans==n)printf("YES\n");
    else printf("NO\n");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值