Created
August 6, 2014 14:48
-
-
Save jackliusr/3b4ac7c3d78e53dc040f to your computer and use it in GitHub Desktop.
Sherlock and GCD
This file contains hidden or 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
object Solution { | |
def main(args: Array[String])={ | |
val lines = io.Source.stdin.getLines.drop(1) | |
def gcd(a: Int, b: Int) : Int = if(b == 0) a else gcd(b, a % b) | |
val tcs = lines.grouped(2).map( v => v(1)).map(l=>l.split("\\s+").map( s => s.toInt)) | |
val results = tcs.map(c => c.reduceLeft(gcd)) | |
results.foreach( r => println(if( r > 1) "NO" else "YES" )) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment