Multiplicatively perfect numbers: Difference between revisions

Added BASIC256, True BASIC, PureBasic and Yabasic.
(→‎{{header|Go}}: Updated in line with C example of which it is a translation.)
(Added BASIC256, True BASIC, PureBasic and Yabasic.)
Line 99:
Up to 500000 there are 108223 multiplicatively perfect numbers and 108326 semi-primes
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">arraybase 1
limit = 500
dim Divisors(1)
c = 0
 
print "Special numbers under "; limit; ":"
 
for n = 1 to limit
pro = 1
for m = 2 to ceil(n / 2)
if n mod m = 0 then
pro *= m
c += 1
redim Divisors(c)
Divisors[c] = m
end if
next m
ub = Divisors[?]
if n = pro and ub > 2 then
print rjust(string(n), 3); " = "; rjust(string(Divisors[ub-1]), 2); " x "; rjust(string(Divisors[ub]), 3)
end if
next n</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">LET limit = 50
DIM divisors(0)
LET c = 1
 
PRINT "Special numbers under"; limit; ":"
 
FOR n = 1 TO limit
LET pro = 1
FOR m = 2 TO ceil(n/2)
IF remainder(n, m) = 0 THEN
LET pro = pro*m
MAT REDIM divisors(c)
LET divisors(c) = m
LET c = c+1
END IF
NEXT m
LET ub = UBOUND(divisors)
IF n = pro AND ub > 1 THEN PRINT USING "### = ## x ###": n, divisors(ub-1), divisors(ub)
NEXT n
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">Macro Ceil (_x_)
Round(_x_, #PB_Round_Up)
EndMacro
 
OpenConsole()
Define.i limit = 500
Dim Divisors.i(1)
Define.i n, pro, m, c = 0, ub
 
PrintN("Special numbers under" + Str(limit) + ":")
 
For n = 1 To limit
pro = 1
For m = 2 To Ceil(n / 2)
If Mod(n, m) = 0:
pro * m
ReDim Divisors(c) : Divisors(c) = m
c + 1
EndIf
Next m
ub = ArraySize(Divisors())
If n = pro And ub > 1:
PrintN(RSet(Str(n),3) + " = " + RSet(Str(Divisors(ub-1)),2) + " x " + RSet(Str(Divisors(ub)),3))
EndIf
Next n
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">limit = 500
dim Divisors(1)
c = 1
 
print "Special numbers under", limit, ":"
 
for n = 1 to limit
pro = 1
for m = 2 to ceil(n / 2)
if mod(n, m) = 0 then
pro = pro * m
dim Divisors(c) : Divisors(c) = m
c = c + 1
fi
next m
ub = arraysize(Divisors(), 1)
if n = pro and ub > 1 then
print n using "###", " = ", Divisors(ub-1) using "##", " x ", Divisors(ub) using "###"
fi
next n</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
2,130

edits