Skip to content

Instantly share code, notes, and snippets.

@DarkHole1
Last active July 1, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkHole1/95131c40cdadbb43b500138c80953009 to your computer and use it in GitHub Desktop.
Save DarkHole1/95131c40cdadbb43b500138c80953009 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;
void main() {
readln;
readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
auto n = sqrt(cast(real)a.parse!long);
if(n == 1) return "NO";
if(n % 1 == 0 && isPrime(cast(long)n)) return "YES";
return "NO";
}
bool isPrime(long n) {
foreach(i; 2..cast(long)sqrt(cast(real)n) + 1) if(n % i == 0) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment