Created
August 7, 2019 11:46
-
-
Save alexmelyon/9889ebd742ef17d42fcb7807f0d3f45a to your computer and use it in GitHub Desktop.
Revisions
-
alexmelyon revised this gist
Aug 7, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ fun main() { val list = listOf(24, 36, 145, 48, 72L) list.reduce { total, next -> lcm(total, next) }.let { println(it) } } /** -
alexmelyon created this gist
Aug 7, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ fun main() { val list = listOf(24, 36, 145, 48, 72L) list.reduce { total, next -> lcm(total, next) }.let { println(it) } list.reduce { total, next -> total * next }.let { println(it) } } /** * НОК Наименьшее общее кратное */ fun lcm(a: Long, b: Long): Long { return a / gcd(a, b) * b } /** * НОД Наибольший общий делитель */ fun gcd(a: Long, b: Long): Long { return if (b == 0L) a else gcd(b, a % b) }