Advertisement
mfgnik

Untitled

Nov 15th, 2020
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5.  
  6. int main() {
  7.     const int N = 1000000;
  8.     std::vector<int>numbers(N+1);
  9.     std::vector<int> primes;
  10.  
  11.     for (int i=2; i<=N; ++i) {
  12.         if (numbers[i] == 0) {
  13.             numbers[i] = i;
  14.             primes.push_back(i);
  15.         }
  16.         for (int j=0; j<(int)primes.size() && primes[j]<=numbers[i] && i*primes[j]<=N; ++j)
  17.             numbers[i * primes[j]] = primes[j];
  18.     }
  19.     int amount_numbers;
  20.     std::cin >> amount_numbers;
  21.     while (amount_numbers--) {
  22.         int64_t current_number;
  23.         std::cin >> current_number;
  24.         auto sqrt = std::sqrt(current_number);
  25.         auto sqrt_int = static_cast<int>(sqrt);
  26.         if (sqrt == sqrt_int && numbers[sqrt_int] == sqrt_int) {
  27.             std::cout << "YES";
  28.         } else {
  29.             std::cout << "NO";
  30.         }
  31.         std::cout << " ";
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement