-
-
Save choo8489/4902c1ec638d56383540 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 java.io.{FileInputStream, FileOutputStream} | |
import scala.io.StdIn | |
object calendar extends App{ | |
def gcd(a: Long,b: Long): Long = { if(b ==0) a else gcd(b, a%b) } | |
Console.setIn(new FileInputStream("example.in")) | |
// Console.setIn(new FileInputStream("A-large-practice.in")) | |
// Console.setOut(new FileOutputStream("A-large-practice.out")) | |
def solve(sets: String): Long = { | |
val Array(month, day_month, day_week) = sets.split(" ").map(_.toLong) | |
val nset = day_week / gcd(day_month, day_week) | |
val lines = for(i <- 0L until nset) yield { | |
val n = ((day_month % day_week) * i) % day_week + day_month | |
if(n % day_week == 0) n / day_week else n / day_week + 1 | |
} | |
(month/nset) * lines.sum + lines.take((month%nset).toInt).sum | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { num => | |
val sets = StdIn.readLine() | |
println(f"Case #$num: ${solve(sets)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment