048 Self powers.pl 429 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
  6. # https://projecteuler.net/problem=48
  7. # Runtime: 0.048s
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use ntheory qw(powmod);
  12. my $sum = 0;
  13. my $mod = 10**10;
  14. foreach my $i (1 .. 1000) {
  15. $sum += powmod($i, $i, $mod);
  16. $sum %= $mod;
  17. }
  18. say $sum;