Switch game

描述

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 ).

輸入

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

輸出

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

樣例輸入

1
5

樣例輸出

1

0


先把這些燈標上號,1 2 3 4 5 6 7 8 ……無窮
首先全是關的,也就是全是0
第一次操作 ,標號是1的倍數,全都變成相反的狀態,也就是全變成1.。
第二次操作 ,標號是2的倍數,全都變成相反的狀態,你可以看下,2 4 6……變成了0.。。
第三次操作 ,標號是3的倍數,全都變成相反的狀態,你可以看下,3 6 9……

他問你 N 號檯燈最後 變成了 什麼狀態,
例如 1號燈,最後變成了1,不管多少次操作都是1.。
例如 5號燈 最後變成了0,不管多少次操作都是0.。

當操作次數大於N的時候 N的狀態就不會改變了,因爲N不會是M(M>N)的倍數。。


思路很簡單就是求n有幾個約數(包括1和自身)如果有奇數個約數,則是變奇數次,結果也就是1;否則爲0



#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
    int n,k;
    while(scanf("%d",&n)!=EOF)
    {
        k=0;
        for(int i=1;i<=n;i++)
        {
            if(n%i==0)
                k++;
        }
        if(k%2==0)
          printf("0\n");
        else
            printf("1\n");
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章