Write a script to generate first 20 Chowla Numbers,
named after, Sarvadaman D. S. Chowla, a London born Indian American mathematician.
It is defined as:
C(n) = (sum of divisors of n) - 1 - n
proc chowla {n} {
set sum 0
for {set i 2} {[expr $i * $i] <= $n} {incr i} {
if {[expr $n % $i]==0} {
set sum [expr $sum + $i]
set j [expr int($n / $i)]
if {$j != $i} {
set sum [expr $sum + $j]
}
}
}
return $sum
}
for {set i 1} {$i <= 20} {incr i} {
puts "chowla($i) = [chowla $i]"
}
沒有留言:
張貼留言