The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
Solution (In Ruby)
The solution to this problem becomes simple if we just directly implement with the brute force technique. It just costs two lines in Ruby and the source code is given below.
sum = (1..1000).to_a.inject(0) {|b,i| b+= i**i}.to_s puts sum.to_s[(sum.size-10)..(sum.size)]Hover here to see the solution.
Cheers!!
Bragaadeesh
No comments:
Post a Comment