Last active
July 1, 2018 14:31
-
-
Save DarkHole1/95131c40cdadbb43b500138c80953009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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