Skip to content

Instantly share code, notes, and snippets.

@soursop
Created December 26, 2014 16:44
Show Gist options
  • Save soursop/4afdeea7a982c89e224c to your computer and use it in GitHub Desktop.
Save soursop/4afdeea7a982c89e224c to your computer and use it in GitHub Desktop.
FairWarning.scala
object Main {
def solve(input:List[BigInt]):BigInt = {
def gcd(): BigInt = {
val diffs = input.sliding(2).map(x => (x(0) - x(1)).abs).toList
if (1 == diffs.length) {
diffs(0)
} else {
diffs.foldLeft(BigInt(0))(_ gcd _)
}
}
val gcdNum = gcd()
val r = input.head % gcdNum
if (r == 0) 0 else gcdNum - r
}
def main(args:Array[String]) = {
val writer = new java.io.PrintWriter("a-large.out")
try {
process(io.Source.fromFile("B-large-practice.in").getLines)(writer.println)
} finally {
writer.flush()
writer.close()
}
}
def process(lineIn: Iterator[String])(lineOut: String => Unit) = {
for (i <- 1 to lineIn.next().toInt) {
val answer = solve(lineIn.next().split(" ").toList.map(BigInt(_)).tail)
println(i)
lineOut(s"Case #$i: $answer")
}
}
}
@soursop
Copy link
Author

soursop commented Dec 26, 2014

원인을 알았습니다!
첫번째 수가 24이고 공배수가 5인 경우 24%5의 나머지 값은 1입니다.
이경우 공배수-나머지수를 계산해야 원하는 수가 나옵니다!!! 공배수-나머지값 처리를 안해서 large가 안풀렸던 거였네요 ㅠ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment