自学内容网 自学内容网

每日一题洛谷P5736 【深基7.例2】质数筛c++

#include<iostream>
using namespace std;
int main() {
int n;
int s[100000] = { 0 };
cin >> n;
int t = 0;
for (int i = 0; i < n; i++) {
cin >> t;
if (t == 2 || t == 3 || t == 5 || t == 7)cout << t << " ";
else {
if (t != 1) {
if (t % 2 != 0 && t % 3 != 0 && t % 5 != 0 && t % 7 != 0) {
int flag = 1;
for (int j = 2; j * j <= t; j++) {
if (t % j == 0) {
flag = 0;
break;
}
}
if (flag)cout << t << " ";
}
}
}
}
return 0;
}


原文地址:https://blog.csdn.net/2401_88089822/article/details/145434496

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!