Anti-primes: Difference between revisions

No edit summary
 
(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
do oncecnt =1 for 1
while n endmod p = /*j*/0
end cnt += /*once*/1
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 = ffn(.n) {
if .n < 2: return 1
for[=2] .i = 2; .i <= .n\2; .i += 1 {
Line 3,814 ⟶ 3,846:
 
The &nbsp; #DIVS &nbsp; function could be further optimized by only processing &nbsp; ''even'' &nbsp; numbers, with unity being treated as a special case.
<syntaxhighlight lang="rexx">/*REXX program finds and displays N number of anti─primes oranti-primes highly─composite(highly-composite) numbers.*/
parseParse argArg N . /* obtain optional argument from the CL. */
ifIf N=='' | N=="," thenThen N= 20 /* Not specified? Then use the default. */
maxD= 0 /* the maximum number of divisors so far */
saySay '─index─-index- ──anti─prime──--anti-prime--' /* display a title forFor the numbers shown */
#nn= 0 /* the count of anti─primesanti-primes found " " */
Do i=1 For 59 While nn<N /* step through possible numbers by twos */
do once=1 for 1
d=nndivs(i) do i=1 for 59 /* get nn divisors; /*step through possible numbers by twos*/
If d>maxD Then Do d= #divs(i); if d<=maxD then iterate /*get #found divisors;an anti-prime Isnn set new maxD too small? Skip.*/
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) if #>=N then leave once right(i,10) /*if wedisplay havethe enoughindex anti─primes,and donethe anti-prime. */
end /*i*/End
End /*i*/
 
Do do ji=60 by 20 While nn<N /* step through possible numbers by 20. */
d=nndivs(i)
d= #divs(j); if d<=maxD then iterate /*get # divisors; Is too small? Skip.*/
If d>maxD Then Do #= # + 1; maxD= d /* found an anti─prime #;anti-prime nn set new minD.maxD */
maxD=d
say center(#, 7) right(j, 10) /*display the index and the anti─prime.*/
nn=nn+1
if #>=N then leave /*if we have enough anti─primes, done. */
saySay center(#nn, 7) right(i, 10) /* display the index and the anti─primeanti-prime. */
end /*j*/
End
end /*once*/
End /*i*/
exit /*stick a fork in it, we're all done. */
Exit #= # + 1; maxD= d /*found anstick anti─primea #;fork in setit, newwe're minDall done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*-----------------------------------------------------------------------------------*/
#divs: procedure; parse arg x 1 y /*X and Y: both set from 1st argument.*/
nndivs: Procedure if x<3 then return x /* compute the number of proper /*handle special cases for onedivisors and two.*/
Parse Arg x
if x==4 then return 3 /* " " " " four. */
If x<2 Then
if x<6 then return 2 /* " " " " three or five*/
Return 1
odd= x // 2 /*check if X is odd or not. */
odd=x//2
if odd then #= 1 /*Odd? Assume Pdivisors count of 1.*/
n=1 else do; #= 3; y= x % 2 /*Even? " /* 1 is a proper divisor " " " 3.*/
Do j=2+odd by 1+odd While j*j<x /* test all endpossible integers /* [↑] start with known num of Pdivs.*/
exit /*stick aup To but excluding sqrt(x) fork in it, we're all done. */
 
If x//j==0 Then do k=3 for x%2-3 by 1+odd while k<y /*for oddj numbersis a divisor,so is x%j skip evens.*/
n=n+2
if x//k==0 then do; #= # + 2 /*if no remainder, then found a divisor*/
End
y= x % k /*bump # Pdivs, calculate limit Y. */
If j*j==x Then /* If x is a square if k>=y then do; #= # - 1; leave; end /*limit?*/
n=n+1 end /* sqrt(x) is a proper divisor ___ */
n=n+1 else if k /*k> x is a proper divisor then leave /*only divide up to x */
Return n</syntaxhighlight>
end /*k*/ /* [↑] this form of DO loop is faster.*/
return #+1 /*bump "proper divisors" to "divisors".*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 20 </tt>}}
<pre>
Line 4,433 ⟶ 4,465:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
System.print("The first 20 anti-primes are:")
885

edits