RosettaCodeData/Task/Arithmetic-Rational/Zkl/arithmetic-rational-2.zkl

9 lines
323 B
Plaintext

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 "."));
}