Numbers whose count of divisors is prime: Difference between revisions
Numbers whose count of divisors is prime (view source)
Revision as of 00:06, 28 August 2022
, 1 year agosyntax highlighting fixup automation
Alextretyak (talk | contribs) (Added 11l) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 11:
{{trans|FreeBASIC}}
<
I a == 2
R 1B
Line 35:
print()
print("\n\nFound "row‘ numbers’)</
{{out}}
Line 62:
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<
INT FUNC CountDivisors(INT x)
Line 99:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Numbers_whose_count_of_divisors_is_prime.png Screenshot from Atari 8-bit computer]
Line 123:
=={{header|ALGOL 68}}==
Counts the divisors without using division.
<
INT max number := 1 000;
TO 2 DO
Line 145:
max number := 100 000
OD
END</
{{out}}
<pre>
Line 163:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_WHOSE_COUNT_OF_DIVISORS_IS_PRIME.AWK
BEGIN {
Line 201:
return(1)
}
</syntaxhighlight>
{{out}}
<pre>
Line 220:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<
if v < 2 then return False
if (v mod 2) = 0 then return v = 2
Line 248:
print
print "Found "; row; " numbers"
end</
==={{header|FreeBASIC}}===
<
If ValorEval < 2 Then Return False
If ValorEval Mod 2 = 0 Then Return ValorEval = 2
Line 280:
Print !"\n\nFound"; row; " numbers"
Sleep</
{{out}}
<pre>Numbers which count of divisors is prime are:
Line 306:
{{works with|QuickBasic}}
{{trans|FreeBASIC}}
<
PRINT "Numbers which count of divisors is prime are:"
Line 335:
WEND
isPrime = True
END FUNCTION</
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
Line 383:
Input()
CloseConsole()
End</
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<
print "Numbers which count of divisors is prime are:"
Line 415:
end while
return True
end sub</
{{out}}
<pre>
Line 423:
=={{header|C++}}==
<
#include <cstdlib>
#include <iomanip>
Line 488:
std::cout << "\nCount: " << count << '\n';
return EXIT_SUCCESS;
}</
{{out}}
Line 512:
=={{header|CLU}}==
<
div_counts = proc (n: int) returns (sequence[int])
divs: array[int] := array[int]$fill(1,n,1)
Line 559:
end
stream$putl(po, "\nFound " || int$unparse(count) || " numbers.")
end start_up</
{{out}}
<pre> 4 9 16 25 49 64 81 121 169 289
Line 573:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
// Numbers whose divisor count is prime. Nigel Galloway: July 13th., 2021
primes64()|>Seq.takeWhile(fun n->n*n<100000L)|>Seq.collect(fun n->primes32()|>Seq.skip 1|>Seq.map(fun g->pown n (g-1))|>Seq.takeWhile((>)100000L))|>Seq.sort|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 584:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
math.primes.factors math.ranges sequences sequences.extras ;
FROM: math.extras => integer-sqrt ;
Line 594:
[ sq ] [ divisors length odd-prime? ] map-filter ;
100,000 pdc-upto 10 group [ [ "%-8d" printf ] each nl ] each</
{{out}}
<pre>
Line 609:
=={{header|Go}}==
{{libheader|Go-rcu}}
<
import (
Line 657:
}
fmt.Printf("\n\nFound %d such integers (%d under 1,000).\n", len(results), under1000)
}</
{{out}}
Line 679:
For a suitable definition of `is_prime`, see [[Erd%C5%91s-primes#jq]].
<
def count_divisors:
Line 700:
1000, 100000
| "\nn with odd prime divisor counts, 1 < n < \(.):",
(range(1;.) | select(count_divisors | (. > 2 and is_prime)))</
{{out}}
<pre>
Line 732:
=={{header|Julia}}==
<
ispdc(n) = (ndivs = prod(collect(values(factor(n))).+ 1); ndivs > 2 && isprime(ndivs))
foreach(p -> print(rpad(p[2], 8), p[1] % 10 == 0 ? "\n" : ""), enumerate(filter(ispdc, 1:100000)))
</
<pre>
4 9 16 25 49 64 81 121 169 289
Line 749:
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
maxPrime = NextPrime[Sqrt@max, -1];
maxPower = NextPrime[Log[2, max], -1];
Line 758:
TableForm, "Numbers up to 1000 with prime divisor counts:", Top]
Labeled[Partition[ans, UpTo[8]] //
TableForm, "Numbers up to 100,000 with prime divisor counts:", Top]</
{{out}}<pre>
Line 781:
Checking only divisors of squares (see discussion).
<
Line 823:
for i, n in list:
stdout.write &"{n:5}", if (i + 1) mod 10 == 0: '\n' else: ' '
echo()</
{{out}}
Line 840:
=={{header|Pascal}}==
<
{$IFDEF FPC}
// {$R+,O+} //debuging purpose
Line 1,176:
writeln;
SpeedTest(pD,4000*1000*1000);
END.</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 10
Line 1,203:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use ntheory <is_prime divisors>;
push @matches, $_**2 for grep { is_prime divisors $_**2 } 1..int sqrt 1e5;
print @matches . " matching:\n" . (sprintf "@{['%6d' x @matches]}", @matches) =~ s/(.{72})/$1\n/gr;</
{{out}}
<pre>79 matching:
Line 1,220:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">return</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">2</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
Line 1,228:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d < %,d found: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 1,237:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my $ceiling = ceiling sqrt 1e5;
Line 1,246:
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</
{{out}}
<pre>79 matching:
Line 1,259:
=={{header|REXX}}==
<
parse arg hi cols . /*obtain optional arguments from the CL*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the defaults*/
Line 1,307:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,337:
=={{header|Ring}}==
<
load "stdlib.ring"
row = 0
Line 1,362:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,376:
=={{header|Sidef}}==
<
say "Positive integers under #{limit.commify} whose number of divisors is an odd prime:"
1..limit -> grep { !.is_prime && .sigma0.is_prime }.each_slice(10, {|*a|
say a.map{'%6s' % _}.join(' ')
})</
{{out}}
<pre>
Line 1,399:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<
import "/seq" for Lst
import "/fmt" for Fmt
Line 1,414:
for (chunk in Lst.chunks(results, 10)) Fmt.print("$,7d", chunk)
var under1000 = results.count { |r| r < 1000 }
System.print("\nFound %(results.count) such integers (%(under1000) under 1,000).")</
{{out}}
Line 1,432:
=={{header|XPL0}}==
<
int N, I;
[if N <= 1 then return false;
Line 1,458:
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
]</
{{out}}
|