-
-
Save soursop/4afdeea7a982c89e224c to your computer and use it in GitHub Desktop.
FairWarning.scala
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
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") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
원인을 알았습니다!
첫번째 수가 24이고 공배수가 5인 경우 24%5의 나머지 값은 1입니다.
이경우 공배수-나머지수를 계산해야 원하는 수가 나옵니다!!! 공배수-나머지값 처리를 안해서 large가 안풀렸던 거였네요 ㅠ