paranid5

1_thread

May 13th, 2021
526
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import kotlin.concurrent.thread
  2.  
  3. fun printNums(start: Int, finish: Int) = thread {
  4.     (start..finish).forEach(::println)
  5. }
  6.  
  7. fun main() {
  8.     val (m, n) = readLine()!!.trim().split(' ').map { it.toInt() }
  9.     val numbersInThreads = IntArray(n) { m / n }
  10.     val ost = m - n * (m / n)
  11.  
  12.     (0 until ost).forEach { numbersInThreads[it]++ }
  13.  
  14.     var cur = 1
  15.  
  16.     (0 until n).forEach {
  17.         printNums(cur, cur + numbersInThreads[it] - 1)
  18.         cur += numbersInThreads[it]
  19.     }
  20. }
RAW Paste Data