水题一个,模拟实现就好。
源代码:
#include <iostream>
#include<vector>
using namespace std;
class Prison
{
private:
vector<int> locked;
vector<int> unlocked;
int N;
public:
void Init()
{
cin>>N;
locked.clear();
unlocked.clear();
locked.resize(N+1,1);
unlocked.resize(N+1,0);
}
void Gaming()
{
int temp=N;
for(int i=1;i<=N;++i)
for (int j=i;j<=N;)
{
if(unlocked[j])
{
unlocked[j]=0;
locked[j]=1;
}
else
{
unlocked[j]=1;
locked[j]=0;
}
j+=i;
}
}
int Escape()
{
int temp=0;
for (int i=1;i<=N;++i)
temp+=unlocked[i];
return temp;
}
};
int main()
{
int M;
cin>>M;
while (M--)
{
Prison P;
P.Init();
P.Gaming();
cout<<P.Escape()<<endl;
}
return 0;
}