Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,33 @@
search.limit% = 20000
dim sumf%(search.limit%)
print "Searching up to"; search.limit%; "for amicable pairs:"
rem - create a table of proper divisor sums
for a% = 1 to search.limit%
sumf%(a%) = 1
next a%
for a% = 2 to search.limit%
b% = a% + a%
while (b% > 0) and (b% <= search.limit%)
sumf%(b%) = sumf%(b%) + a%
b% = b% + a%
wend
next a%
rem - search for pairs
count% = 0
a% = 2
while a% < search.limit%
b% = sumf%(a%)
rem - protect against invalid array index
if b% <= 0 or b% >= search.limit% then b% = 2
rem - otherwise, we're good to go
if (b% > a%) and (a% = sumf%(b%)) then \
print using "##### #####"; a%; b% : \
count% = count% + 1
a% = a% + 1
wend
print count%; "pairs were found"
end

View file

@ -0,0 +1,43 @@
include Settings
say version; say 'Amicable pairs'; say
arg n
numeric digits 16
if n = '' then
n = 20000
show = (n > 0); n = Abs(n)
/* Get amicable pairs */
a = Amicables(n)
say time('e') a 'amicable pairs collected'
/* Show amical pairs */
if show then do
do i = 1 to a
say time('e') amic.amicable.1.i 'and' amic.amicable.2.i 'are an amicable pair'
end
end
say time('e') 'seconds'
exit
Amicables:
/* Amicable number pairs */
procedure expose glob. amic.
arg x
/* Init */
amic. = 0
/* Scan for amicable pairs */
n = 0
do i = 1 to x
s = Sigma(i)-i; glob.sigma.i = s
if i = glob.sigma.s then do
if s = i then
iterate
n = n+1
amic.amicable.1.n = s; amic.amicable.2.n = i
end
end
amic.0 = n
return n
include Numbers
include Functions
include Abend