基础题。
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 105;
int lock[MAXN]; //牢房是否上锁,-1表示上锁,1表示打开
int main()
{
int T;
cin >> T;
while (T--)
{
memset(lock, -1, sizeof(lock));
int n;
cin >> n;
for (int i = 1; i <= n; i++) //重复n次
{
for (int j = i; j <= n; j += i)
lock[j] *= -1;
}
int total = 0; //打开的牢房的数量
for (int i = 1; i <= n; i++)
{
if (lock[i] == 1)
++total;
}
cout << total << endl;
}
return 0;
}
继续加油。