首页 > 其他 > 详细

hdu 2053 Switch Game

时间:2014-03-16 00:49:51      阅读:562      评论:0      收藏:0      [点我收藏+]
Problem Description
There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).
 

 

Input
Each test case contains only a number n ( 0< n<= 10^5) in a line.
 

 

Output
Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).
 

 

Sample Input
1
5
 

 

Sample Output
1
0
Hint
hint
Consider the second test case:
The initial condition :0 0 0 0 0 …
After the first operation : 1 1 1 1 1 …
After the second operation : 1 0 1 0 1 …
After the third operation : 1 0 0 0 1 …
After the fourth operation : 1 0 0 1 1 …
After the fifth operation : 1 0 0 1 0 …
The later operations cannot change the condition of the fifth lamp any more. So the answer is 0.
这题是水题,找出n的约数的个数count,若为偶数则是0,若为奇数则为1;代码如下:
bubuko.com,布布扣
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,i,count;
    while(scanf("%d",&n)!=EOF)
    {
        count=0;
        for(i=1;i<=sqrt(n);i++)//求n的约数的个数
        {
            if(n%i==0)
            {
                count+=2;
                if(i==n/i)
                    count--;
            }
        }
        if(count%2==0) printf("0\n");
        else printf("1\n");
    }
    return 0;
}
bubuko.com,布布扣

 

 

hdu 2053 Switch Game,布布扣,bubuko.com

hdu 2053 Switch Game

原文:http://www.cnblogs.com/duan-to-success/p/3602121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!