-
-
Save myeesan/191a1db48f189f861bcc 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 scala.io.Source | |
import java.io.PrintWriter | |
object FairWarning { | |
val in = Source.fromFile("small.in").getLines | |
val out = new PrintWriter("small.out") | |
def main(args: Array[String]) { | |
val n = in.next.toInt | |
val lines = in.take(n).toList | |
val rs = lines.map(line => TestCase(line.tail).solve) | |
rs.zipWithIndex foreach { case (res, idx) => out.println(s"Case #${idx + 1}: $res") } | |
out.flush() | |
} | |
case class TestCase(_line: String) { | |
def secList = (_line split (" ")).tail map (BigInt(_)) | |
def solve = { | |
val first = secList.head | |
val subs = secList.tail.map(x => (first - x).abs).filterNot(_ == 0) | |
val gcd = subs.foldLeft(subs.head)(_ gcd _) | |
val res = gcd - first % gcd | |
if (res == first || res == BigInt("1")) 0 else res | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment