Project Euler problem 48

Self powers

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.

Link to original description
Source code examples on Github

Python and erlang ok with big integers and simple brutforce solution working fast:

Python version

1
2
3
4
5
6
7
8
#!/usr/bin/python3

from functools import reduce

answer = reduce(lambda x,y: x+pow(y,y), range(1,1001)) % pow(10,10)

print(answer)

Erlang version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname p47
% vim:syn=erlang

-mode(compile).

main(_) ->
    Answer = lists:foldl(fun(E,A)-> pow(E,E) + A end, 0, lists:seq(1,1000)) rem pow(10,10),
    io:format("Answer: ~p ~n", [Answer]).

pow(_, 0) -> 1;
pow(A, B) -> A*pow(A, B-1).