BestCoder#51

时间:2021-09-18 06:12:17
 #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
bool visit[];
int prime[]; void init_prim()
{
memset(visit, true, sizeof(visit));
int num = ;
for (int i = ; i <= ; ++i)
{
if (visit[i] == true)
{
num++;
prime[num] = i;
}
for (int j = ; ((j <= num) && (i * prime[j] <= )); ++j)
{
visit[i * prime[j]] = false;
if (i % prime[j] == ) break;
}
}
}
int main() {
memset(prime, , sizeof(prime));
int T, n;
init_prim();
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
bool flag = true;
if(n < 1e6) {
if(n == ) {
printf("%d\n", );
} else if(visit[n] == true){
printf("%d\n", n-);
} else {
printf("%d\n", );
}
} else {
for(int i = ; prime[i] <= sqrt(n); ++i) {
if(n % prime[i] == ) {
flag = false;
printf("%d\n", );
break;
}
}
if(flag) {
printf("%d\n", n-);
}
}
}
return ;
}

第一题

相关文章