main.tcl 389 B

12345678910111213141516171819202122232425
  1. proc gcd {a b} {
  2. if {$b > $a} {
  3. set t $b
  4. set b $a
  5. set a $t
  6. }
  7. while {$b != 0} {
  8. set t $b
  9. set b [expr {$a % $b}]
  10. set a $t
  11. }
  12. return $a
  13. }
  14. proc lcm {a b} {
  15. set g [gcd $a $b]
  16. return [expr {$g * ($a / $g) * ($b / $g)}]
  17. }
  18. set result 1
  19. for {set i 1} {$i <= 20} {incr i} {
  20. set result [lcm $result $i]
  21. }
  22. puts $result