1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream> #include<string> #include<cstring> #include<algorithm> using namespace std; int n, m; bool prime[10000005]; int main(){ memset(prime, true, sizeof(prime)); cin >> n >> m; prime[0] = prime[1] = false; for (int i = 2; i <= n; i++) { if (!prime[i])continue; for (int j = 2 * i; j <= n; j += i) { prime[j] = false; } } for (int i = 1; i <= m; i++) { int tmp; cin >> tmp; cout << (prime[tmp]?"Yes":"No") << endl; } } |
洛谷 P3383 【模板】线性筛素数
发表评论