1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <cmath> #include <cctype> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm>
#define int long long #define random(x) ((1ll * rand() << 30 ^ 1ll * rand() << 15 ^ rand()) % (x) + 1)
using namespace std;
struct IOManager { template <typename T> inline bool read(T &x) { char c = '\n'; bool flag = false; x = 0; while (~ c && ! isdigit(c = getchar()) && c != '-') ; c == '-' && (flag = true, c = getchar()); if (! ~ c) return false; while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar(); return (flag && (x = -x), true); } inline bool read(char &c) { c = '\n'; while (~ c && ! (isprint(c = getchar()) && c != ' ')) ; return ~ c; } inline int read(char s[]) { char c = '\n'; int len = 0; while (~ c && ! (isprint(c = getchar()) && c != ' ')) ; if (! ~ c) return 0; while (isprint(c) && c != ' ') s[len ++] = c, c = getchar(); return (s[len] = '\0', len); } template <typename T> inline IOManager operator > (T &x) { read(x); return *this; } template <typename T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void write(char c) { putchar(c); } inline void write(char s[]) { int pos = 0; while (s[pos] != '\0') putchar(s[pos ++]); } template <typename T> inline IOManager operator < (T x) { write(x); return *this; } } io;
struct Solver { private: int n; void input() { io > n; } int multiple(int a, int b, int mod) { int ret = 0; a %= mod; while (b) { b & 1 && ((ret += a) %= mod), (a <<= 1) %= mod, b >>= 1; } return ret; } int power(int a, int b, int mod) { int ret = 1; a %= mod; while (b) { b & 1 && ((ret *= a) %= mod), (a *= a) %= mod, b >>= 1; } return ret; } bool is_prime(int n) { if (n == 2) return true; if (n < 2 || ! (n & 1)) return false; int c = 0, p = n - 1, cnt = 30; while (! (p & 1)) ++ c, p >>= 1; while (cnt --) { int a = random(n - 1), x = power(a, p, n); for (int i = 0; i < c; ++ i) { int y = multiple(x, x, n); if (y == 1 && x != 1 && x != n - 1) return false; x = y; } if (x != 1) return false; } return true; } void process() { int a; io > a; int q = sqrt(a); for (int i = 2; i <= q; ++ i) if (! (a % i) && is_prime(i) && is_prime(a / i)) { io < (char *) "Yes\n"; return; } io < (char *) "No\n"; }
public: void solve() { input(); while (n --) process(); } } solver;
signed main() { solver.solve(); return 0; }
|