Project Euler #48: Self powers

  • + 1 comment

    Python 3 100% 1-liner

    print(int(str(sum(pow(i, i, 10**10) for i in range(1, int(input())+1)))[-10:]))
    
    • + 0 comments

      The above is not the most computationally efficient.

      If you don't count import statements againsed the "1-liner" qualifier, the following is better:

      ` from functools import reduce

      print(reduce(lambda a, b: (a+b) % (10**10), [pow(i, i, 10**10) for i in range(1, int(input())+1)])) `