# ZeroJudge - b513: 判斷質數-商競103 ### 題目連結:https://zerojudge.tw/ShowProblem?problemid=b513 ###### tags: `ZeroJudge` `數學` `數論` `質數` ```cpp= #include <iostream> using namespace std; #define SIZE 65536 int primes[SIZE], primeAmount; bool notPrime[SIZE] = { true, true }; static const auto Initialize = [] { cin.sync_with_stdio(false); cin.tie(nullptr); for (int i = 2; i < SIZE; ++i) { if (!notPrime[i]) { primes[primeAmount] = i; ++primeAmount; } for (int j = 0; i * primes[j] < SIZE; ++j) { notPrime[i * primes[j]] = true; if (!(i % primes[j])) break; } } return nullptr; }(); int main() { int times, number; cin >> times; while (times--) { cin >> number; cout << (notPrime[number] ? 'N' : 'Y') << '\n'; } } ```