I wrote some code that is supposed to sum n^n for 1 <= n <= 1000. Here's the code:
sum = 0
(1..1000).each do |n|
sum += n**n
puts "n = #{n}, sum = #{sum}"
end
For some reason, the output is coming out negative after number 28:
n = 29, sum = -2015400977700573523892329442490139437391867
Any idea why this is happening?