Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- seivePrimes();
- for (int i = 0; i < n; i++) {
- long a = sc.nextLong();
- long sqrt = (int) Math.sqrt(a);
- if (a >= 4 && sqrt * sqrt == a) {
- if (isPrime((int) sqrt)) {
- System.out.println("YES");
- } else {
- System.out.println("NO");
- }
- } else {
- System.out.println("NO");
- }
- }
- sc.close();
- }
- static int maxlim = 1000000;
- private static void seivePrimes() {
- for (int i = 3; i * i <= maxlim; i += 2) {
- if (!isNotPrime[(i - 3) / 2]) {
- for (int j = i; i * j <= maxlim; j += 2) {
- isNotPrime[(i * j - 3) / 2] = true;
- }
- }
- }
- }
- static boolean[] isNotPrime = new boolean[(maxlim - 3) / 2 + 1];
- private static boolean isPrime(int t) {
- if (t == 2)
- return true;
- if (t % 2 == 0)
- return false;
- else
- return !isNotPrime[(t - 3) / 2];
- }
- }
- #include <iostream>
- #include <set>
- using namespace std;
- const int sqrt_lim = 1000001;
- set<long long> prime_squares()
- {
- static bool arr[sqrt_lim];
- for (int i = 2; i*i < sqrt_lim; i++)
- {
- if (!arr[i])
- {
- for (int j = i*i; j < sqrt_lim; j += i)
- {
- arr[j] = true;
- }
- }
- }
- set<long long> res;
- for (int i = 2; i < sqrt_lim; i++)
- {
- if (!arr[i])
- res.insert((long long)i * i);
- }
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false); cin.tie(NULL);
- set<long long> sq(prime_squares());
- int n; cin >> n;
- for (int i = 0; i < n; i++)
- {
- long long x; cin >> x;
- if (sq.find(x) != sq.end())
- {
- cout << "YESn";
- }
- else
- {
- cout << "NOn";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement