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,28 @@
rem - return true (-1) if n is perfect, otherwise 0
def fn.isperfect%(n%)
sum% = 1 : rem 1 is a divisor of every number
f1% = 2
f2% = 1 : rem dummy value to start
while (f1% * f1%) <= n%
if n% = (n% / f1%) * f1% then \
sum% = sum% + f1% : \
f2% = n% / f1% : \
sum% = sum% + f2%
rem don't double count sqrt of perfect square!
if f1% = f2% then sum% = sum% - f2%
f1% = f1% + 1
wend
fn.isperfect% = (sum% = n%)
return
fend
print "Searching to 10000 for perfect numbers"
count% = 0
for i% = 2 to 10000
if fn.isperfect%(i%) then \
print i% : count% = count% + 1
next i%
print count%; "were found"
end

View file

@ -0,0 +1,16 @@
100 sub isperfect(n)
110 if (n < 2) or (n mod 2 = 1) then isperfect = false
120 sum = 1
130 for i = 2 to sqr(n)
140 if n mod i = 0 then
150 sum = sum+i
160 q = int(n/i)
170 if q > i then sum = sum+q
180 endif
190 next
200 isperfect = n = sum
210 end sub
220 print "The first 4 perfect numbers are:"
230 for i = 2 to 10000
240 if isperfect(i) then print i;" ";
250 next i

View file

@ -0,0 +1,18 @@
Print "The first 4 perfect numbers are:"
For i = 2 To 10000
If isPerfect(i) <> 0 Then Print i; " ";
Next i
Function isPerfect (n)
If n < 2 Then isPerfect = 0
If n Mod 2 = 1 Then isPerfect = 0
sum = 1
For i = 2 To Sqr(n)
If n Mod i = 0 Then
sum = sum + i
q = n \ i
If q > i Then sum = sum + q
End If
Next
If n = sum Then isPerfect = -1 Else isPerfect = 0
End Function