Skip to content

Commit 3705102

Browse files
committed
[euler/prob021] add problem 21
1 parent e18dc35 commit 3705102

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

euler/prob021-gerdr.pl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use v6;
2+
3+
sub d(Int \n) {
4+
my $sum = 1;
5+
my \sqrt-n = sqrt n;
6+
7+
for 2..Int(sqrt-n) -> \a {
8+
my \b = n div a;
9+
$sum += a + b if a * b == n;
10+
}
11+
12+
sqrt-n ~~ Int ?? $sum - sqrt-n !! $sum
13+
}
14+
15+
my $sum = 0;
16+
17+
for 1..10_000 -> \a {
18+
my \b = d(a);
19+
$sum += a + b if a < b and d(b) == a;
20+
}
21+
22+
say $sum;

0 commit comments

Comments
 (0)