Anti-primes: Difference between revisions
→{{header|langur}}
Space Ghost (talk | contribs) No edit summary |
Langurmonkey (talk | contribs) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1,623:
=={{header|Delphi}}==
See [[#Pascal]].
=={{header|EasyLang}}==
{{trans|FutureBasic}}
<syntaxhighlight lang=easylang>
func divcnt v .
n = v
tot = 1
p = 2
while p <= sqrt n
n = n div p
.
p += 1
tot *= cnt
.
if n > 1
tot *= 2
.
return tot
.
while count < 20
n += 1
divs = divcnt n
if divs > max
print n
max = divs
count += 1
.
.
</syntaxhighlight>
=={{header|Elixir}}==
{{trans|Erlang}}<syntaxhighlight lang="elixir">defmodule AntiPrimes do
Line 2,671 ⟶ 2,703:
=={{header|langur}}==
{{trans|D}}
<syntaxhighlight lang="langur">val .countDivisors =
if .n < 2: return 1
for[=2] .i = 2; .i <= .n\2; .i += 1 {
Line 3,814 ⟶ 3,846:
The #DIVS function could be further optimized by only processing ''even'' numbers, with unity being treated as a special case.
<syntaxhighlight lang="rexx">/*REXX program finds and displays
maxD=
Do i=1 For 59 While nn<N /* step through possible numbers by twos */
▲ do once=1 for 1
d=nndivs(i)
If d>maxD Then Do
maxD=d
#= # + 1; maxD= d /*found an anti─prime #; set new minD.*/▼
nn=nn+1
say center(#, 7) right(i, 10) /*display the index and the anti─prime.*/▼
Say center(nn,7)
End /*i*/
Do
d=nndivs(i)
If d>maxD Then Do
maxD=d
nn=nn+1
▲ end /*j*/
End
▲ end /*once*/
End /*i*/
exit /*stick a fork in it, we're all done. */▼
/*-----------------------------------------------------------------------------------*/
nndivs: Procedure
Parse Arg x
If x<2 Then
Return 1
odd=x//2
n=1
Do j=2+odd by 1+odd While j*j<x /* test all
If x//j==0 Then
n=n+2
End
If j*j==x Then /* If x is a square
n=n+1
n=n+1
Return n</syntaxhighlight>
{{out|output|text= when using the default input of: <tt> 20 </tt>}}
<pre>
Line 4,433 ⟶ 4,465:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="
System.print("The first 20 anti-primes are:")
|