[Codeforces] Surprise Language Round #8 D. Chocolate Bar

Surprise Language Round #8 D. Chocolate Bar

  • Time : O(sqrt(k))
  • Space : O(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*
import kotlin.math.sqrt

fun solve(n: Int, m: Int, k: Int) : String {
for(i in 1 .. sqrt(k.toDouble()).toInt()) {
if(k % i != 0) continue
if(n >= i && m >= k / i) return "Yes"
if(m >= i && n >= k / i) return "Yes"
}
return "No"
}

fun main(args: Array<String>) {
val r = Scanner(System.`in`)
val tc = r.nextInt();
for(i in 1 .. tc) {
val n = r.nextInt();
val m = r.nextInt();
val k = r.nextInt();
println(solve(n,m,k))
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/07/15/PS/Codeforces/surprise-language-round-8-d/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.