RosettaCodeData/Task/Arithmetic-Rational/Perl-6/arithmetic-rational-1.pl6

12 lines
374 B
Raku
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
(2..2**19).hyper.map: -> $candidate {
2013-04-10 22:43:41 -07:00
my $sum = 1 / $candidate;
for 2 .. ceiling(sqrt($candidate)) -> $factor {
if $candidate %% $factor {
$sum += 1 / $factor + 1 / ($candidate / $factor);
}
}
2016-12-05 22:15:40 +01:00
if $sum.nude[1] == 1 {
2013-04-10 22:43:41 -07:00
say "Sum of reciprocal factors of $candidate = $sum exactly", ($sum == 1 ?? ", perfect!" !! ".");
}
}