Attractive numbers: Difference between revisions

(Add CLU)
Line 2,419:
69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116 117 118 119 120</pre>
 
=={{header|Objeck}}==
{{trans|Java}}
 
<lang objeck>class AttractiveNumber {
function : Main(args : String[]) ~ Nil {
max := 120;
"The attractive numbers up to and including {$max} are:"->PrintLine();
count := 0;
for(i := 1; i <= max; i += 1;) {
n := CountPrimeFactors(i);
if(IsPrime(n)) {
" {$i}"->Print();
if(++count % 20 = 0) {
""->PrintLine();
};
};
};
 
""->PrintLine();
}
function : IsPrime(n : Int) ~ Bool {
if(n < 2) {
return false;
};
 
if(n % 2 = 0) {
return n = 2;
};
 
if(n % 3 = 0) {
return n = 3;
};
 
d := 5;
while(d *d <= n) {
if(n % d = 0) {
return false;
};
d += 2;
if(n % d = 0) {
return false;
};
d += 4;
};
 
return true;
}
function : CountPrimeFactors(n : Int) ~ Int {
if(n = 1) {
return 0;
};
 
if(IsPrime(n)) {
return 1;
};
 
count := 0;
f := 2;
while(true) {
if(n % f = 0) {
count++;
n /= f;
if(n = 1) { return count; };
if(IsPrime(n)) { f := n; };
}
else if(f >= 3) {
f += 2;
}
else {
f := 3;
};
};
 
return -1;
}
}</lang>
 
=={{header|Pascal}}==
760

edits