#pragma warning disable using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Runtime.CompilerServices; using static System.Console; using static System.Math; using static Util; using System.Diagnostics; #region using(AtCoder等非対応) // using pii = (int, int); // using pll = (long, long); // using pdd = (double, double); // using pss = (string, string); // using pis = (int, string); // using psi = (string, int); // using pls = (long, string); // using psl = (string, long); // using pds = (double, string); // using psd = (string, double); // using pid = (int, double); // using pdi = (double, int); // using pld = (long, double); // using pdl = (double, long); // using vb = bool[]; // using vvb = bool[][]; // using vvvb = bool[][][]; // using vi = int[]; // using vvi = int[][]; // using vvvi = int[][][]; // using vl = long[]; // using vvl = long[][]; // using vvvl = long[][][]; // using vd = double[]; // using vvd = double[][]; // using vvvd = double[][][]; // using vs = string[]; // using vvs = string[][]; // using vvvs = string[][][]; // using listb = System.Collections.Generic.List; // using llistb = System.Collections.Generic.List>; // using lllistb = System.Collections.Generic.List>>; // using listi = System.Collections.Generic.List; // using llisti = System.Collections.Generic.List>; // using lllisti = System.Collections.Generic.List>>; // using listl = System.Collections.Generic.List; // using llistl = System.Collections.Generic.List>; // using lllistl = System.Collections.Generic.List>>; // using listd = System.Collections.Generic.List; // using llistd = System.Collections.Generic.List>; // using lllistd = System.Collections.Generic.List>>; // using lists = System.Collections.Generic.List; // using llists = System.Collections.Generic.List>; // using lllists = System.Collections.Generic.List>>; // using mii = System.Collections.Generic.SortedDictionary; // using mll = System.Collections.Generic.SortedDictionary; // using mss = System.Collections.Generic.SortedDictionary; // using mis = System.Collections.Generic.SortedDictionary; // using msi = System.Collections.Generic.SortedDictionary; // using mls = System.Collections.Generic.SortedDictionary; // using msl = System.Collections.Generic.SortedDictionary; // using umii = System.Collections.Generic.Dictionary; // using umll = System.Collections.Generic.Dictionary; // using umss = System.Collections.Generic.Dictionary; // using umis = System.Collections.Generic.Dictionary; // using umsi = System.Collections.Generic.Dictionary; // using umls = System.Collections.Generic.Dictionary; // using umsl = System.Collections.Generic.Dictionary; // using seti = System.Collections.Generic.SortedSet; // using setl = System.Collections.Generic.SortedSet; // using sets = System.Collections.Generic.SortedSet; // using useti = System.Collections.Generic.HashSet; // using usetl = System.Collections.Generic.HashSet; // using usets = System.Collections.Generic.HashSet; #endregion class Util { public static double PI = 3.141592653589793; public static long m107 = 1000000007; public static long m998 = 998244353; public static int a10_9 = 1000000000; public static long a10_18 = 1000000000000000000; public static int iinf = 1 << 30; public static long linf = (1l << 61) - (1l << 31); /// 1行読みこみ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string read() => ReadLine(); /// 1行読みこみ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string readln() => ReadLine(); /// 1行読みこみ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string readline() => ReadLine(); /// 改行なし出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void write() => Write(""); /// 改行なし出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void write(T value) => Write(value); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void writeln() => WriteLine(""); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void writeln(T value) => WriteLine(value); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void writeline() => WriteLine(""); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void writeline(T value) => WriteLine(value); /// 改行なし出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void print() => Write(""); /// 改行なし出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void print(T value) => Write(value); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void println() => WriteLine(""); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void println(T value) => WriteLine(value); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printline() => WriteLine(""); /// 改行あり出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printline(T value) => WriteLine(value); /// 任意の要素数・初期値の配列を作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] makearr(int num, T value) { var arr = new T[num]; for (int i = 0; i < num; ++i) arr[i] = value; return arr; } // end of func /// 任意の要素数・初期値の2次元配列を作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[][] makearr2(int height, int width, T value) { var arr = new T[height][]; for (int i = 0; i < height; ++i) { arr[i] = new T[width]; for (int j = 0; j < width; ++j) { arr[i][j] = value; } } return arr; } // end of func /// 任意の要素数・初期値の3次元配列を作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[][][] makearr3(int height, int width, int depth, T value) { var arr = new T[height][][]; for (int i = 0; i < height; ++i) { arr[i] = new T[width][]; for (int j = 0; j < width; ++j) { arr[i][j] = new T[depth]; for (int k = 0; k < depth; ++k) { arr[i][j][k] = value; } } } return arr; } // end of func /// 任意の要素数・初期値のListを作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List makelist(int num, T value) { return new List(makearr(num, value)); } // end of func /// 任意の要素数・初期値の2次元Listを作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List> makelist2(int height, int width, T value) { var arr = new List>(); for (int i = 0; i < height; ++i) { arr.Add(makelist(width, value)); } return arr; } // end of func /// 任意の要素数・初期値の3次元Listを作って初期化する [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List>> makelist3(int height, int width, int depth, T value) { var arr = new List>>(); for (int i = 0; i < height; ++i) { arr[i] = new List>(); for (int j = 0; j < width; ++j) { arr[i].Add(makelist(depth, value)); } } return arr; } // end of func /// 1次元配列のディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] copyarr(T[] arr) { T[] brr = new T[arr.Length]; Array.Copy(arr, brr, arr.Length); return brr; } // end of func /// 2次元配列のディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[][] copyarr2(T[][] arr) { T[][] brr = new T[arr.Length][]; for (int i = 0; i < arr.Length; ++i) { brr[i] = new T[arr[i].Length]; Array.Copy(arr[i], brr[i], arr[i].Length); } return brr; } // end of func /// 3次元配列のディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[][][] copyarr3(T[][][] arr) { T[][][] brr = new T[arr.Length][][]; for (int i = 0; i < arr.Length; ++i) { brr[i] = new T[arr[i].Length][]; for (int j = 0; j < arr[i].Length; ++j) { brr[i][j] = new T[arr[i][j].Length]; Array.Copy(arr[i][j], brr[i][j], arr[i][j].Length); } } return brr; } // end of func /// 1次元Listのディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List copylist(List list) { return new List(list); } // end of func /// 2次元Listのディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List> copylist2(List> list) { List> list2 = new List>(); for (int i = 0; i < list.Count; ++i) { list2.Add(new List(list[i])); } return list2; } // end of func /// 3次元Listのディープコピーを行う [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List>> copylist3(List>> list) { List>> list2 = new List>>(); for (int i = 0; i < list.Count; ++i) { List> tmplist = new List>(); for (int j = 0; j < list[i].Count; ++i) { tmplist.Add(new List(list[i][j])); } list2.Add(tmplist); } return list2; } // end of func /// 1次元Listを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printlist(List list) { WriteLine(string.Join(" ", list)); } // end of func /// 1次元配列を出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printlist(T[] list) { WriteLine(string.Join(" ", list)); } // end of func /// 2次元リストを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printlist2(List> list) { foreach (var l in list) { WriteLine(string.Join(" ", l)); } } // end of func /// 2次元配列を出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printlist2(T[][] list) { foreach (var l in list) { WriteLine(string.Join(" ", l)); } } // end of func /// 1次元Listを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printarr(List list) { WriteLine(string.Join(" ", list)); } // end of func /// 1次元配列を出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printarr(T[] list) { WriteLine(string.Join(" ", list)); } // end of func /// 2次元リストを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printarr2(List> list) { foreach (var l in list) { WriteLine(string.Join(" ", l)); } } // end of func /// 2次元配列を出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printarr2(T[][] list) { foreach (var l in list) { WriteLine(string.Join(" ", l)); } } // end of func /// ジェネリックを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printiter(IEnumerable generic) { foreach (var it in generic) { Write(it + " "); } WriteLine(); } // end of func /// ジェネリックを出力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void printlineiter(IEnumerable generic) { foreach (var it in generic) { WriteLine(it + " "); } } // end of func /// 数字を1つint型で読み込み [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int readint() { return int.Parse(ReadLine()); } // end of func /// 数字を1つlong型で読み込み [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long readlong() { return long.Parse(ReadLine()); } // end of func /// 入力を空白区切りのstringで返す(変則的な入力に対応) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] readsplit() { return ReadLine().Split(' '); } // end of func /// 数字をスペース区切りでint型で入力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int[] readints() { return ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray(); } // end of func /// 数字をスペース区切りでlong型で入力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long[] readlongs() { return ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray(); } // end of func /// 数字をスペース区切りでfloat型で入力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float[] readfloats() { return ReadLine().Split(' ').Select(_ => float.Parse(_)).ToArray(); } // end of func /// 数字をスペース区切りでdouble型で入力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double[] readdoubles() { return ReadLine().Split(' ').Select(_ => double.Parse(_)).ToArray(); } // end of func /// 文字列をスペース区切りで入力 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] readstrings() { return ReadLine().Split(' '); } // end of func /// 読み込んだint2つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, int) readintt2() { var arr = readints(); return (arr[0], arr[1]); } // end of func /// 読み込んだint3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, int, int) readintt3() { var arr = readints(); return (arr[0], arr[1], arr[2]); } // end of func /// 読み込んだint4つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, int, int, int) readintt4() { var arr = readints(); return (arr[0], arr[1], arr[2], arr[3]); } // end of func /// 読み込んだlong2つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (long, long) readlongt2() { var arr = readlongs(); return (arr[0], arr[1]); } // end of func /// 読み込んだ数long3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (long, long, long) readlongt3() { var arr = readlongs(); return (arr[0], arr[1], arr[2]); } // end of func /// 読み込んだ数long4つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (long, long, long, long) readlongt4() { var arr = readlongs(); return (arr[0], arr[1], arr[2], arr[3]); } // end of func /// 読み込んだfloat2つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (float, float) readfloatt2() { var arr = readfloats(); return (arr[0], arr[1]); } // end of func /// 読み込んだfloat3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (float, float, float) readfloatt3() { var arr = readfloats(); return (arr[0], arr[1], arr[2]); } // end of func /// 読み込んだfloat4つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (float, float, float, float) readfloatt4() { var arr = readfloats(); return (arr[0], arr[1], arr[2], arr[3]); } // end of func /// 読み込んだdouble2つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (double, double) readdoublet2() { var arr = readdoubles(); return (arr[0], arr[1]); } // end of func /// 読み込んだdouble3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (double, double, double) readdoublet3() { var arr = readdoubles(); return (arr[0], arr[1], arr[2]); } // end of func /// 読み込んだdouble4つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (double, double, double, double) readdoublet4() { var arr = readdoubles(); return (arr[0], arr[1], arr[2], arr[3]); } // end of func /// 読み込んだstring2つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (string, string) readstringt2() { var arr = ReadLine().Split(' '); return (arr[0], arr[1]); } // end of func /// 読み込んだstring3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (string, string, string) readstringt3() { var arr = ReadLine().Split(' '); return (arr[0], arr[1], arr[2]); } // end of func /// 読み込んだstring3つをタプルで返す(分解代入用) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (string, string, string, string) readstringt4() { var arr = ReadLine().Split(' '); return (arr[0], arr[1], arr[2], arr[3]); } // end of func /// 先頭に要素数(int)と次にでかい数字1つ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, long) readintlongt2() { var arr = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); return ((int)arr[0], arr[1]); } // end of func /// 先頭に要素数(int)と次にでかい数字2つ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, long, long) readintlongt3() { var arr = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); return ((int)arr[0], arr[1], arr[2]); } // end of func /// 先頭に要素数(int)と次にでかい数字2つ [MethodImpl(MethodImplOptions.AggressiveInlining)] public static (int, long, long, long) readintlongt4() { var arr = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); return ((int)arr[0], arr[1], arr[2], arr[3]); } // end of func /// 小数点以下を16桁で表示(精度が厳しい問題に対応) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteLine16(T num) { WriteLine(string.Format("{0:0.################}", num)); } // end of func /// 整数を二進数で表示 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteLine2bit(int num) { WriteLine(Convert.ToString(num, 2)); } // end of func /// 整数を二進数で表示 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteLine2bit(long num) { WriteLine(Convert.ToString(num, 2)); } // end of func /// 整数を2進数表現した文字列に [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string IntToString2bit(int num) { return Convert.ToString(num, 2); } // end of func /// 整数を2進数表現した文字列に [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string LongToString2bit(long num) { return Convert.ToString(num, 2); } // end of func /// 出力のflush削除 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void preprocess() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; System.Console.SetOut(sw); } // end of func /// 出力をflush [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void finalprocess() { System.Console.Out.Flush(); } // end of func } // end of class /// 座標に便利(値型だけど16byteまではstructが速い) struct YX { public int y; public int x; public YX(int y, int x) { this.y = y; this.x = x; } } // end of class /// グラフをするときに(値型だけど16byteまではstructが速い) struct Edge { public int from; public int to; public long cost; public Edge(int from, int to, long cost) { this.from = from; this.to = to; this.cost = cost; } } // end of class class Kyopuro { public static void Main() { preprocess(); var kyopuro = new Kyopuro(); kyopuro.Solve(); finalprocess(); } // end of func [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsPrime(long num) { if (num == 2) return true; // 2未満の数と偶数は素数ではない if (num < 2l || num % 2l == 0) return false; // n - 1 = 2^s * d と表す long s = 0; long d = num - 1; while (d % 2l == 0) { ++s; d /= 2l; } // var rand = new long[] { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 }; // foreach (var r in rand) { var rand = new Random(); for (int i = 0; i < 10; ++i) { long r = rand.NextInt64(2, num - 1); long x = KurikaeshiPow(r, d, num); if (x == 1l || x == num - 1l) continue; for (long j = 0; j < s - 1l; ++j) { x = KurikaeshiPow(x, 2, num); if (x == 1l) return false; if (x == num - 1) break; } if (x != num - 1) return false; } return true; } // a^b mod n を計算する関数 public static long ModPow(long a, long b, long n) { long result = 1; a %= n; while (b > 0) { if (b % 2 == 1) result = (result * a) % n; b /= 2; a = (a * a) % n; } return result; } /// a^nを繰り返し二乗法 [MethodImpl(MethodImplOptions.AggressiveInlining)] public long KurikaeshiPow(long a, long n, long mod = long.MaxValue) { if (n == 0) return 1; if (n == 1) return a % mod; long ret = 1; while (n > 0) { // a^(2^k) をかけていく k = nを二進数表現したときに1が立っているbit if ((n & 1) == 1) ret = (ret * a) % mod; n >>= 1; a = (a * a) % mod; } return ret; } // end of method public void Solve() { // writeline(IsPrime(2)); // return; // var sw = new Stopwatch(); // sw.Start(); long lmax = 100000l; var prr = new List(new long[1] { 2 }); var arr = new bool[lmax + 1]; for (int i = 2; i <= lmax; i += 2) arr[i] = false; for (int i = 3; i <= lmax; i += 2) { if (arr[i]) continue; prr.Add(i); int ii = i; while (ii <= lmax) { arr[ii] = true; ii += i; } } // sw.Stop(); // writeline(sw.Elapsed); // return; int q = readint(); for (int i = 0; i < q; ++i) { long a = readlong(); foreach (long p in prr) { if (a % p != 0) continue; a /= p; break; } if (a == 1) { writeline("No"); continue; } foreach (long p in prr) { if (a % p != 0) continue; a /= p; break; } if (a == 1) { writeline("No"); continue; } writeline(IsPrime(a) ? "Yes" : "No"); } } // end of method } // end of class