How to resolve the algorithm Anti-primes step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Anti-primes step by step in the Ring programming language
Table of Contents
Problem Statement
The anti-primes (or highly composite numbers, sequence A002182 in the OEIS) are the natural numbers with more factors than any smaller than itself.
Generate and show here, the first twenty anti-primes.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Anti-primes step by step in the Ring programming language
Source code in the ring programming language
# Project : Anti-primes
see "working..." + nl
see "wait for done..." + nl + nl
see "the first 20 anti-primes are:" + nl + nl
maxDivisor = 0
num = 0
n = 0
result = list(20)
while num < 20
n = n + 1
div = factors(n)
if (div > maxDivisor)
maxDivisor = div
num = num + 1
result[num] = n
ok
end
see "["
for n = 1 to len(result)
if n < len(result)
see string(result[n]) + ","
else
see string(result[n]) + "]" + nl + nl
ok
next
see "done..." + nl
func factors(an)
ansum = 2
if an < 2
return(1)
ok
for nr = 2 to an/2
if an%nr = 0
ansum = ansum+1
ok
next
return ansum
# find the first 20 antiprimes
# - numbers woth more divisors than the previous numbers
numberOfDivisorCounts = 0
maxDivisor = 0
num = 0
n = 0
result = list(20)
while num < 20
n += 1
if n > numberOfDivisorCounts
# need a bigger table of divisor counts
numberOfDivisorCounts += 5000
ndc = list(numberOfDivisorCounts)
for i = 1 to numberOfDivisorCounts
ndc[ i ] = 1
next
for i = 2 to numberOfDivisorCounts
j = i
while j <= numberOfDivisorCounts
ndc[ j ] = ndc[ j ] + 1
j += i
end
next
ok
div = ndc[ n ]
if (div > maxDivisor)
maxDivisor = div
num += 1
result[num] = n
ok
end
see result[1]
for n = 2 to len(result)
see " " + string(result[n])
next
You may also check:How to resolve the algorithm Nth root step by step in the Swift programming language
You may also check:How to resolve the algorithm Deceptive numbers step by step in the Prolog programming language
You may also check:How to resolve the algorithm Euler method step by step in the Maple programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Perl programming language