From 3fe81ee22644939fc29238b00b90c7239b1046bb Mon Sep 17 00:00:00 2001 From: yenru0 Date: Thu, 18 Sep 2025 13:49:59 +0900 Subject: [PATCH] complete 34088.kt --- storage/zeta/kt/completed/34088.kt | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 storage/zeta/kt/completed/34088.kt diff --git a/storage/zeta/kt/completed/34088.kt b/storage/zeta/kt/completed/34088.kt new file mode 100644 index 0000000..744e55b --- /dev/null +++ b/storage/zeta/kt/completed/34088.kt @@ -0,0 +1,60 @@ +import kotlin.math.absoluteValue +import kotlin.math.max +import kotlin.math.sqrt + +fun getAllDivisor(x: Int): List { + val divs = mutableListOf() + + for (i in 2..sqrt(x.toDouble()).toInt()) { + if (x % i == 0) { + val oppo = x / i + if (oppo != i) { + divs.add(oppo) + } + divs.add(i) + } + + } + + divs.add(x) + return divs +} + + +fun modmod(arr: List): Int { + if (arr.size == 1) { + return 1 + } + var maxGroupSize = -1 + + maxGroupSize = max(arr.count { it % 2 == 0 }, arr.count { it % 2 == 1 }) + + for (i in 0 until 24) { + val a = arr.random() + val b = arr.random() + + if ((a - b).absoluteValue <= 1) { + continue + } + + val divs = getAllDivisor((a - b).absoluteValue) + + for (div in divs) { + val alpha = a % div + + maxGroupSize = max(arr.count { it % div == alpha }, maxGroupSize) + } + } + + return maxGroupSize +} + + +fun main() = with(System.`in`.bufferedReader()) { + this.readLine().toInt() + + val arr = this.readLine().split(' ').map { it.toInt() } + + println(modmod(arr)) + +} \ No newline at end of file