Attractive numbers: Difference between revisions

no edit summary
(Add Comal)
No edit summary
Line 4,003:
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|Vlang}}==
{{trans|Go}}
<lang vlang>fn is_prime(n int) bool {
if n < 2 {
return false
}
else if n%2 == 0 {
return n == 2
}
else if n%3 == 0 {
return n == 3
}
else {
mut d := 5
for d*d <= n {
if n%d == 0 {
return false
}
d += 2
if n%d == 0 {
return false
}
d += 4
}
return true
}
}
 
fn count_prime_factors(n int) int {
mut nn := n
if n == 1 {
return 0
}
else if is_prime(nn) {
return 1
}
else {
mut count, mut f := 0, 2
for {
if nn%f == 0 {
count++
nn /= f
if nn == 1{
return count
}
if is_prime(nn) {
f = nn
}
} else if f >= 3{
f += 2
} else {
f = 3
}
}
return count
}
}
 
fn main() {
max := 120
println('The attractive numbers up to and including $max are:')
mut count := 0
for i in 1 .. max+1 {
n := count_prime_factors(i)
if is_prime(n) {
print('${i:4}')
count++
if count%20 == 0 {
println('')
}
}
}
}</lang>
 
{{out}}
<pre>
The attractive numbers up to and including 120 are:
4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34
35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68
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|Wren}}==
338

edits