aboutsummaryrefslogtreecommitdiff
path: root/challenge-140/abigail/tcl/ch-2.tcl
blob: cc64678c3bb4abab099d439fe5db939b810d11ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# See ../README.md
#

#
# Run as: tclsh ch-2.tcl < input-file
#

while {[gets stdin line] >= 0} {
    lassign [split $line " "] i j k
    set n 0
    while {$k > 0} {
        incr n
        set s [expr isqrt ($n)]
        for {set d 1} {$d <= $s} {incr d} {
            if {$n % $d == 0} {
                if {$d <= $i && $n / $d <= $j} {incr k -1}
                if {$d <= $j && $n / $d <= $i} {incr k -1}
                if {$n == $d * $d}             {incr k}
            }
        }
    }
    puts $n
}