Jump to content

Anti-primes: Difference between revisions

Added Kotlin
(Added C)
(Added Kotlin)
Line 81:
 
{{out}}
<pre>
The first 20 anti-primes are:
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
 
=={{header|Kotlin}}==
{{trans|Go}}
<lang scala>// Version 1.3.10
 
fun countDivisors(n: Int): Int {
if (n < 2) return 1;
var count = 2 // 1 and n
for (i in 2..n / 2) {
if (n % i == 0) count++
}
return count;
}
 
fun main(args: Array<String>) {
println("The first 20 anti-primes are:")
var maxDiv = 0
var count = 0
var n = 1
while (count < 20) {
val d = countDivisors(n)
if (d > maxDiv) {
print("$n ")
maxDiv = d
count++
}
n++
}
println()
}</lang>
 
{{output}}
<pre>
The first 20 anti-primes are:
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.