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