input:light.in output:light.out

时间限制: 1000 ms 空间限制: 524288 KB

题目描述

输入

输出

样例输入

1
2
5
1 1 0 1 1

样例输出

1
3

数据范围限制

提示

按动 1、4 、5 号开关

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
#define rr register
int n,a[100005],ans;
signed main()
{
freopen("light.in","r",stdin);
freopen("light.out","w",stdout);
scanf("%d",&n);
for(rr int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(rr int i=n;i>=1;i--)
{
if(a[i])
{
ans++;
a[i]=false;
for(rr int j=1;j<=sqrt(i);j++)
{
if(i%j==0 && j==sqrt(i))
{
a[j]=!a[j];
continue;
}
if(i%j==0)
{
a[j]=!a[j];
a[i/j]=!a[i/j];
}
}
}
}
printf("%d",ans);
}