Erdős-Nicolas numbers: Difference between revisions

Erdős-Nicolas numbers in in various dialects BASIC
(Upgraded to 'full' task.)
(Erdős-Nicolas numbers in in various dialects BASIC)
Line 78:
91963648 equals the sum of its first 142 divisors
</pre>
 
 
=={{header|BASIC}}==
Rosetta Code problem: https://rosettacode.org/wiki/Erdős-Nicolas_numbers
by Jjuanhdez, 02/2023
 
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="freebasic">limite = 400000
dim DSum(limite+1) fill 1
dim DCount(limite+1) fill 1
 
for i = 2 to limite
j = i + i
while j <= limite
if DSum[j] = j then
print rjust(j,8); " equals the sum of its first "; rjust(DCount[j],3); " divisors"
end if
DSum[j] += i
DCount[j] += 1
j += i
end while
next i</syntaxhighlight>
{{out}}
<pre>24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">Dim As Uinteger limite = 2e6
Dim As Uinteger DSum(limite+1), DCount(limite+1)
Dim As Integer i, j
 
For i = 0 To limite
DSum(i) = 1
DCount(i) = 1
Next i
 
For i = 2 To limite
j = i + i
While j <= limite
If DSum(j) = j Then
Print Using "######## equals the sum of its first ### divisors"; j; DCount(j)
End If
DSum(j) += i
DCount(j) += 1
j += i
Wend
Next i</syntaxhighlight>
{{out}}
<pre> 24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">limite = 50000
DIM DSum(limite + 1), DCount(limite + 1)
 
FOR i = 0 TO limite
DSum(i) = 1
DCount(i) = 1
NEXT i
 
FOR i = 2 TO limite
j = i + i
WHILE j <= limite
IF DSum(j) = j THEN
PRINT USING "######## equals the sum of its first ### divisors"; j; DCount(j)
END IF
DSum(j) = DSum(j) + i
DCount(j) = DCount(j) + 1
j = j + i
WEND
NEXT i</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="lb">limite = 1000000-1
'Maximum array size is 1,000,001 elements
dim DSum(limite+1)
dim DCount(limite+1)
 
for i = 0 to limite
DSum(i) = 1
DCount(i) = 1
next i
 
for i = 2 to limite
j = i + i
while j <= limite
if DSum(j) = j then
print using("########", j); " equals the sum of its first"; using("###", DCount(j)); " divisors"
end if
DSum(j) = DSum(j) + i
DCount(j) = DCount(j) + 1
j = j + i
wend
next i
</syntaxhighlight>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="PureBasic">OpenConsole()
 
limite.l = 2e6
Dim DSum.l(limite+1)
Dim DCount.l(limite+1)
 
For i.l = 0 To limite
DSum(i) = 1
DCount(i) = 1
Next i
 
For i = 2 To limite
j.l = i + i
While j <= limite
If DSum(j) = j
PrintN(RSet(Str(j), 8) + " equals the sum of its first " + RSet(Str(DCount(j)), 3) + " divisors")
EndIf
DSum(j) = DSum(j) + i
DCount(j) = DCount(j) + 1
j = j + i
Wend
Next i
 
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">limite = 2e6
dim DSum(limite+1), DCount(limite+1)
 
for i = 0 to limite
DSum(i) = 1
DCount(i) = 1
next i
 
for i = 2 to limite
j = i + i
while j <= limite
if DSum(j) = j print j using ("########"), " equals the sum of its first ", DCount(j) using ("###"), " divisors"
DSum(j) = DSum(j) + i
DCount(j) = DCount(j) + 1
j = j + i
wend
next i</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
 
=={{header|C++}}==
2,130

edits