Project Euler Problem 48 Solution

The series, 1^(1) + 2^(2) + 3^(3) + … + 10^(10) = 10405071317.

Find the last ten digits of the series, 1^(1) + 2^(2) + 3^(3) + … + 1000^(1000).

My solution in Ruby:

sum = 0
for i in 1..1000 do
  sum += i**i
end
str = sum.to_s

puts str[str.length - 10,str.length]

UPDATE

s = 0
(1..1000).inject { |s, x| s + x ** x } % (10 ** 10)
str = s.to_s
puts str[str.length - 10,str.length]

2 Replies to “Project Euler Problem 48 Solution”

Leave a Reply

Your email address will not be published. Required fields are marked *