Hdu2053

Switch Game HDU - 2053

Time limit1000 msMemory limit32768 kB

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

InputEach test case contains only a number n ( 0< n<= 10^5) in a line.
OutputOutput the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).Sample Input

1
5

Sample Output

1
0


首先我们得知道,第n次开关改变n的倍数的灯,那么前n盏灯的状态不再改变。所以要知道无限次操作后第n盏灯的状态,只需计算n盏灯n次操作后的状态。
一开始想到的是模拟。时限是一秒,1秒大概能做10^8次操作,而题目的范围是10^10,不出意外TLE了。
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <queue>
 4 #include <vector>
 5 #include<string.h>
 6 #include<map>
 7 #include<bits/stdc++.h>
 8 #define LL long long
 9 #define maxn 100005
10 using namespace std;
11 int a[maxn];
12 int n;
13 int main()
14 {
15     while(scanf("%d",&n)!=EOF)
16     {
17      memset(a,0,sizeof a);
18      for(int i=1;i<=n;i++)
19      {
20          for(int j=1;j<=n;j++)
21          {
22              if((j%i)==0)
23                 a[j]=!a[j];
24          }
25      }
26      printf("%d\n",a[n]);
27     }
28     return 0;
29 }

接着,想到第n盏的开关实际决定与它因数的个数,偶数个因数-0,奇数个因数-1.

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <queue>
 4 #include <vector>
 5 #include<string.h>
 6 #include<map>
 7 #include<bits/stdc++.h>
 8 #define LL long long
 9 #define maxn 100005
10 using namespace std;
11 int n,ans;
12 int main()
13 {
14     while(scanf("%d",&n)!=EOF)
15     {
16         ans=0;//记得初始化
17         for(int i=1;i<=n;i++)
18         if((n%i)==0)
19             ans++;
20         if(ans&1)printf("1\n");
21         else printf("0\n");
22     }
23     return 0;
24 }

 





 

转载于:https://www.cnblogs.com/zuiaimiusi/p/10896211.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值