模拟开关过程,开一盏灯则熄灭数减一,否则加一,累加每次操作后的最大值即可。
AC Code
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
ll n,k,ans,cnt=0;
bool a[1000010];
class cla
{
};
struct str
{
};
namespace funtion
{
void FSIO()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return;
}
};
using namespace funtion;
int main()
{
FSIO();
cin>>n>>k;
for(int i=1;i<=k;i++)
{
ll x,y;
cin>>x;
y=x;
while(y<=n)
{
if(a[y]==1)
{
a[y]=0;
cnt--;
}
else
{
a[y]=1;
cnt++;
}
y+=x;
}
ans=max(ans,cnt);
}
cout<<ans;
return 0;
}