Anti-primes: Difference between revisions

1,269 bytes added ,  11 months ago
Added Anti-Prime Code for Odin
(Initial FutureBasic task solution added)
(Added Anti-Prime Code for Odin)
Line 2,993:
<pre>
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
 
=={{header|Odin}}==
Anti-Primes
Odin Build: dev-2023-07-nightly:3072479c
<syntaxhighlight lang="rust">
package antiprimes
import "core:fmt"
import "core:time"
 
main :: proc() {
sw: time.Stopwatch
time.stopwatch_start(&sw)
AntiPrimeCount, MaxDivisors, Divisors, n: int = 0, 0, 0, 0
MaxAntiPrime: int = 20
fmt.print("\nFirst 20 anti-primes: \n")
fmt.println("----------------------")
for (AntiPrimeCount < MaxAntiPrime) {
n = n + 1
Divisors = DivisorCount(n)
if Divisors > MaxDivisors {
fmt.print(n, " ")
MaxDivisors = Divisors
AntiPrimeCount = AntiPrimeCount + 1
}
}
time.stopwatch_stop(&sw)
dur := sw._accumulation
fmt.println("\n----------------------")
fmt.println("Duration: ", dur)
}
 
DivisorCount :: proc(v: int) -> int {
total, count, a, p: int
total = 1
a = v
for (a % 2 == 0) {
total = total + 1
a = a / 2
}
p = 3
for ((p * p) <= a) {
count = 1
for (a % p == 0) {
count = count + 1
a = a / p
}
p = p + 2
total = total * count
}
if (a > 1) {
total = total * 2
}
return total
}
</syntaxhighlight>
{{out}}
<pre>
First 20 anti-primes:
----------------------
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
----------------------
Duration: 1.6898ms
</pre>
 
37

edits