fork download
  1. fun distribute(num: Int): List<Int> {
  2. var primeFactors: MutableList<Int> = mutableListOf()
  3. var i = 2
  4. var n = num
  5.  
  6. while (n > 1) {
  7. if (n % i == 0) {
  8. primeFactors.add(i)
  9. n /= i
  10. } else {
  11. i++
  12. }
  13. }
  14.  
  15. return primeFactors
  16. }
  17.  
  18. fun main() {
  19. val n = 124
  20.  
  21. val result = distribute(n)
  22.  
  23. println("Czynniki pierwsze liczby $n: $result")
  24. }
Success #stdin #stdout 0.08s 40248KB
stdin
Standard input is empty
stdout
Czynniki pierwsze liczby 124: [2, 2, 31]