RosettaCodeData/Task/Arithmetic-Rational/Zkl/arithmetic-rational-2.zkl
2023-07-01 13:44:08 -04:00

8 lines
323 B
Text

foreach p in ([2 .. (2).pow(19)]){
sum,limit := Rational(1,p), p.toFloat().sqrt();
foreach factor in ([2 .. limit]){
if(p%factor == 0) sum+=Rational(1,factor) + Rational(factor,p);
}
if(sum.b==1) println("Sum of recipr. factors of %6s = %s exactly%s"
.fmt(p, sum, (sum==1) and ", perfect." or "."));
}