HDU 2053 Switch Game

http://acm.hdu.edu.cn/showproblem.php?pid=2053

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
 
代码:
#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;

int a[maxn];

int A(int n)
{
    if(n==0)
        return 1;
    return 0;
}
int B(int i)
{
    for(int j=i;j<=maxn;j+=i)
    {
            a[j]=A(a[j]);
    }
}

int main()
{
    for(int i=1;i<=1e5;i++)
    {
        B(i);
    }
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",a[n]);
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/9244015.html