Sphenic numbers: Difference between revisions

Added FreeBASIC, PureBasic and Yabasic
m (→‎{{header|Raku}}: return a slice rather than an enumerated list)
(Added FreeBASIC, PureBasic and Yabasic)
 
(19 intermediate revisions by 12 users not shown)
Line 329:
The 200,000th sphenic number is 966467 (17 * 139 * 409)
The 5,000th sphenic triplet is {918005, 918006, 918007}"</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">primes: select 1..1666 => prime?
sphenic: []
 
loop 0..dec size primes 'p1 ->
loop (p1+1)..dec size primes 'p2 ->
loop (p2+1)..dec size primes 'p3 ->
try -> 'sphenic ++ primes\[p1] * primes\[p2] * primes\[p3]
 
sphenicBelow1K: sort unique select sphenic 'x -> x < 1000
print "Sphenic numbers up to 1000:"
loop split.every: 15 sphenicBelow1K 'x ->
print map x 's -> pad to :string s 4
 
sphenicBelow10K: select sphenic 'x -> x < 10000
 
sphenicTripletsBelow10K: sort select sphenicBelow10K 'x ->
and? [contains? sphenicBelow10K x+1] [contains? sphenicBelow10K x+2]
 
print ""
print "Sphenic triplets up to 10000:"
loop split.every: 3 sphenicTripletsBelow10K 'x ->
print map x 's [
pad as.code @[s, s+1, s+2] 12
]</syntaxhighlight>
 
{{out}}
 
<pre>Sphenic numbers up to 1000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets up to 10000:
[1309 1310 1311] [1885 1886 1887] [2013 2014 2015]
[2665 2666 2667] [3729 3730 3731] [5133 5134 5135]
[6061 6062 6063] [6213 6214 6215] [6305 6306 6307]
[6477 6478 6479] [6853 6854 6855] [6985 6986 6987]
[7257 7258 7259] [7953 7954 7955] [8393 8394 8395]
[8533 8534 8535] [8785 8786 8787] [9213 9214 9215]
[9453 9454 9455] [9821 9822 9823] [9877 9878 9879]</pre>
 
=={{header|BASIC}}==
==={{header|FreeBASIC}}===
{{trans|XPLo}}
<syntaxhighlight lang="vbnet">Dim Shared Factors(3) As Uinteger
 
Function Sphenic(N As Uinteger) As Boolean
Dim As Uinteger C, F, L, Q
L = Sqr(N)
C = 0
F = 2
Do
Q = N / F
If N Mod F = 0 Then
Factors(C) = F
C += 1
If C > 3 Then Return False
N = Q
If N Mod F = 0 Then Return False
If F > N Then Exit Do
Else
F += 1
If F > L Then
Factors(C) = N
C += 1
Exit Do
End If
End If
Loop
Return Iif(C = 3, True, False)
End Function
 
Dim As Double t0 = Timer
Dim As Uinteger C, N, I
C = 0
N = 2 * 3 * 5
Print "Sphenic numbers less than 1,000:"
Do
If Sphenic(N) Then
C += 1
If N < 1000 Then
Print Using "####"; N;
If C Mod 15 = 0 Then Print
End If
If C = 200000 Then
Print "The 200,000th sphenic number is "; N; " = ";
For I = 0 To 2
Print Factors(I);
If I < 2 Then Print " * ";
Next I
Print
End If
End If
N += 1
If N >= 1e6 Then Exit Do
Loop
Print "There are "; C; " sphenic numbers less than 1,000,000"
 
C = 0
N = 2 * 3 * 5
Print !"\nSphenic triplets less than 10,000:"
Do
If Sphenic(N) Andalso Sphenic(N+1) Andalso Sphenic(N+2) Then
C += 1
If N < 10000 Then
Print "[" & N & ", " & N+1 & ", " & N+2 & "]";
If C Mod 3 = 0 Then Print Else Print ", ";
End If
If C = 5000 Then
Print "The 5000th sphenic triplet is [" & N & ", " & N+1 & ", " & N+2 & "]"
End If
End If
N += 1
If N+2 >= 1e6 Then Exit Do
Loop
Print "There are "; C; " sphenic triplets less than 1,000,000"
 
Print Using "##.##sec."; Timer - t0
 
Sleep</syntaxhighlight>
{{out}}
<pre>Sphenic numbers less than 1,000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
The 200,000th sphenic number is 966467 = 17 * 139 * 409
There are 206964 sphenic numbers less than 1,000,000
 
Sphenic triplets less than 10,000:
[1309, 1310, 1311], [1885, 1886, 1887], [2013, 2014, 2015]
[2665, 2666, 2667], [3729, 3730, 3731], [5133, 5134, 5135]
[6061, 6062, 6063], [6213, 6214, 6215], [6305, 6306, 6307]
[6477, 6478, 6479], [6853, 6854, 6855], [6985, 6986, 6987]
[7257, 7258, 7259], [7953, 7954, 7955], [8393, 8394, 8395]
[8533, 8534, 8535], [8785, 8786, 8787], [9213, 9214, 9215]
[9453, 9454, 9455], [9821, 9822, 9823], [9877, 9878, 9879]
The 5000th sphenic triplet is [918005, 918006, 918007]
There are 5457 sphenic triplets less than 1,000,000
33.90sec.</pre>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">Global Dim Factors(3)
 
Procedure.i Sphenic(N)
Protected C, F, L, Q, res
L = Sqr(N)
C = 0
F = 2
While 1
Q = N / F
If N % F = 0
Factors(C) = F
C + 1
If C > 3 : ProcedureReturn #False : EndIf
N = Q
If N % F = 0 : ProcedureReturn #False : EndIf
If F > N : Break : EndIf
Else
F + 1
If F > L
Factors(C) = N
C + 1
Break
EndIf
EndIf
Wend
If C = 3
res = #True
Else
res = #False
EndIf
ProcedureReturn res
EndProcedure
 
OpenConsole()
t0 = ElapsedMilliseconds()
C = 0
N = 2 * 3 * 5
PrintN("Sphenic numbers less than 1,000:")
While 1
If Sphenic(N)
C + 1
If N < 1000
Print(Str(N) + " ")
If C % 15 = 0 : PrintN("") : EndIf
EndIf
If C = 200000
Print("The 200,000th sphenic number is " + Str(N) + " = ")
For I = 0 To 2
Print(Str(Factors(I)))
If I < 2 : Print(" * ") : EndIf
Next I
PrintN("")
EndIf
EndIf
N + 1
If N >= 1e6 : Break : EndIf
Wend
PrintN("There are " + Str(C) + " sphenic numbers less than 1,000,000")
 
C = 0
N = 2 * 3 * 5
PrintN(#CRLF$ + "Sphenic triplets less than 10,000:")
While 1
If Sphenic(N) And Sphenic(N+1) And Sphenic(N+2)
C + 1
If N < 10000
Print("[" + Str(N) + ", " + Str(N+1) + ", " + Str(N+2) + "]")
If C % 3 = 0 : PrintN("") : Else : Print(", ") : EndIf
EndIf
If C = 5000
PrintN("The 5000th sphenic triplet is [" + Str(N) + ", " + Str(N+1) + ", " + Str(N+2) + "]")
EndIf
EndIf
N + 1
If N+2 >= 1e6 : Break : EndIf
Wend
PrintN("There are " + Str(C) + " sphenic triplets less than 1,000,000")
 
PrintN(StrF((ElapsedMilliseconds() - t0) / 1000, 2) + "sec.")
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry, but takes almost 3 minutes on my on i5 @3.20 GHz</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight>dim Factors(3)
C = 0
N = 2 * 3 * 5
print "Sphenic numbers less than 1,000:"
do
if Sphenic(N) then
C = C + 1
if N < 1000 then
print N using "####";
if mod(C, 15) = 0 print
fi
if C = 2e5 then
print "The 200,000th sphenic number is ", N, " = ";
for I = 0 to 2
print Factors(I);
if I < 2 print " * ";
next I
print
fi
fi
N = N + 1
if N >= 1e6 break
loop
print "There are ", C, " sphenic numbers less than 1,000,000"
 
C = 0
N = 2 * 3 * 5
print "\nSphenic triplets less than 10,000:"
do
if Sphenic(N) and Sphenic(N+1) and Sphenic(N+2) then
C = C + 1
if N < 10000 then
print "[", N, ", ", N+1, ", ", N+2, "]";
if mod(C, 3) = 0 then print else print ", "; : fi
fi
if C = 5000 print "The 5000th sphenic triplet is [", N, ", ", N+1, ", ", N+2, "]"
fi
N = N + 1
if N+2 >= 1e6 break
loop
print "There are ", C, " sphenic triplets less than 1,000,000"
print peek("millisrunning") / 1000, "sec."
end
 
sub Sphenic(N)
local C, F, L, Q
L = sqr(N)
C = 0
F = 2
do
Q = N / F
if mod(N, F) = 0 then
Factors(C) = F
C = C + 1
if C > 3 return false
N = Q
if mod(N, F) = 0 return false
if F > N break
else
F = F + 1
if F > L then
Factors(C) = N
C = C + 1
break
fi
fi
loop
return (C = 3)
end sub</syntaxhighlight>
 
=={{header|C}}==
{{trans|Wren}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <locale.h>
 
bool *sieve(int limit) {
int i, p;
limit++;
// True denotes composite, false denotes prime.
bool *c = calloc(limit, sizeof(bool)); // all false by default
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3; // Start from 3.
while (true) {
int p2 = p * p;
if (p2 >= limit) break;
for (i = p2; i < limit; i += 2 * p) c[i] = true;
while (true) {
p += 2;
if (!c[p]) break;
}
}
return c;
}
 
void primeFactors(int n, int *factors, int *length) {
if (n < 2) return;
int count = 0;
int inc[8] = {4, 2, 4, 2, 4, 6, 2, 6};
while (!(n%2)) {
factors[count++] = 2;
n /= 2;
}
while (!(n%3)) {
factors[count++] = 3;
n /= 3;
}
while (!(n%5)) {
factors[count++] = 5;
n /= 5;
}
for (int k = 7, i = 0; k*k <= n; ) {
if (!(n%k)) {
factors[count++] = k;
n /= k;
} else {
k += inc[i];
i = (i + 1) % 8;
}
}
if (n > 1) {
factors[count++] = n;
}
*length = count;
}
 
int compare(const void* a, const void* b) {
int arg1 = *(const int*)a;
int arg2 = *(const int*)b;
if (arg1 < arg2) return -1;
if (arg1 > arg2) return 1;
return 0;
}
 
int main() {
const int limit = 1000000;
int limit2 = (int)cbrt((double)limit);
int i, j, k, pc = 0, count = 0, prod, res;
bool *c = sieve(limit/6);
for (i = 0; i < limit/6; ++i) {
if (!c[i]) ++pc;
}
int *primes = (int *)malloc(pc * sizeof(int));
for (i = 0, j = 0; i < limit/6; ++i) {
if (!c[i]) primes[j++] = i;
}
int *sphenic = (int *)malloc(210000 * sizeof(int));
printf("Sphenic numbers less than 1,000:\n");
for (i = 0; i < pc-2; ++i) {
if (primes[i] > limit2) break;
for (j = i+1; j < pc-1; ++j) {
prod = primes[i] * primes[j];
if (prod * primes[j+1] >= limit) break;
for (k = j+1; k < pc; ++k) {
res = prod * primes[k];
if (res >= limit) break;
sphenic[count++] = res;
}
}
}
qsort(sphenic, count, sizeof(int), compare);
for (i = 0; ; ++i) {
if (sphenic[i] >= 1000) break;
printf("%3d ", sphenic[i]);
if (!((i+1) % 15)) printf("\n");
}
printf("\nSphenic triplets less than 10,000:\n");
int tripCount = 0, s, t = 0;
for (i = 0; i < count - 2; ++i) {
s = sphenic[i];
if (sphenic[i+1] == s+1 && sphenic[i+2] == s+2) {
tripCount++;
if (s < 9998) {
printf("[%d, %d, %d] ", s, s+1, s+2);
if (!(tripCount % 3)) printf("\n");
}
if (tripCount == 5000) t = s;
}
}
setlocale(LC_NUMERIC, "");
printf("\nThere are %'d sphenic numbers less than 1,000,000.\n", count);
printf("There are %'d sphenic triplets less than 1,000,000.\n", tripCount);
s = sphenic[199999];
int factors[10], length = 0;
primeFactors(s, factors, &length);
printf("The 200,000th sphenic number is %'d (", s);
for (i = 0; i < length; ++i) {
printf("%d", factors[i]);
if (i < length-1) printf("*");
}
printf(").\n");
printf("The 5,000th sphenic triplet is [%d, %d, %d].\n", t, t+1, t+2);
free(c);
free(primes);
free(sphenic);
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Sphenic numbers less than 1,000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets less than 10,000:
[1309, 1310, 1311] [1885, 1886, 1887] [2013, 2014, 2015]
[2665, 2666, 2667] [3729, 3730, 3731] [5133, 5134, 5135]
[6061, 6062, 6063] [6213, 6214, 6215] [6305, 6306, 6307]
[6477, 6478, 6479] [6853, 6854, 6855] [6985, 6986, 6987]
[7257, 7258, 7259] [7953, 7954, 7955] [8393, 8394, 8395]
[8533, 8534, 8535] [8785, 8786, 8787] [9213, 9214, 9215]
[9453, 9454, 9455] [9821, 9822, 9823] [9877, 9878, 9879]
 
There are 206,964 sphenic numbers less than 1,000,000.
There are 5,457 sphenic triplets less than 1,000,000.
The 200,000th sphenic number is 966,467 (17*139*409).
The 5,000th sphenic triplet is [918005, 918006, 918007].
</pre>
 
=={{header|C++}}==
Line 471 ⟶ 942:
The 200,000th sphenic number: 966467 = 17 * 139 * 409
The 5,000th sphenic triplet: (918005, 918006, 918007)
</pre>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System.Linq;
using System.Collections.Generic;
using static System.Console;
 
public static class SphenicNumbers
{
public static void Main()
{
var numbers = FindSphenicNumbers(1_000_000).OrderBy(t => t.N).ToList();
var triplets = numbers.Select(t => t.N).Consecutive().ToList();
 
WriteLine("Sphenic numbers up to 1 000");
numbers.Select(t => t.N).TakeWhile(n => n < 1000).Chunk(15)
.Select(row => row.Delimit()).ForEach(WriteLine);
WriteLine();
 
WriteLine("Sphenic triplets up to 10 000");
triplets.TakeWhile(n => n < 10_000).Select(n => (n-2, n-1, n)).Chunk(3)
.Select(row => row.Delimit()).ForEach(WriteLine);
WriteLine();
 
WriteLine($"Number of sphenic numbers < 1 000 000: {numbers.Count}");
WriteLine($"Number of sphenic triplets < 1 000 000: {triplets.Count}");
var (n, (a, b, c)) = numbers[199_999];
WriteLine($"The 200 000th sphenic number: {n} = {a} * {b} * {c}");
int t = triplets[4_999];
WriteLine($"The 5 000th sphenic triplet: {(t-2, t-1, t)}");
}
 
static IEnumerable<(int N, (int, int, int) Factors)> FindSphenicNumbers(int bound)
{
var primes = PrimeMath.Sieve(bound / 6).ToList();
for (int i = 0; i < primes.Count; i++) {
for (int j = i + 1; j < primes.Count; j++) {
int p = primes[i] * primes[j];
if (p >= bound) break;
for (int k = j + 1; k < primes.Count; k++) {
if (primes[k] > bound / p) break;
int n = p * primes[k];
yield return (n, (primes[i], primes[j], primes[k]));
}
}
}
}
 
static IEnumerable<int> Consecutive(this IEnumerable<int> source)
{
var (a, b, c) = (0, 0, 0);
foreach (int d in source) {
(a, b, c) = (b, c, d);
if (b - a == 1 && c - b == 1) yield return c;
}
}
 
static string Delimit<T>(this IEnumerable<T> source, string separator = " ") =>
string.Join(separator, source);
 
static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T element in source) action(element);
}
}</syntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
Sphenic numbers up to 1 000
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets up to 10 000
(1309, 1310, 1311) (1885, 1886, 1887) (2013, 2014, 2015)
(2665, 2666, 2667) (3729, 3730, 3731) (5133, 5134, 5135)
(6061, 6062, 6063) (6213, 6214, 6215) (6305, 6306, 6307)
(6477, 6478, 6479) (6853, 6854, 6855) (6985, 6986, 6987)
(7257, 7258, 7259) (7953, 7954, 7955) (8393, 8394, 8395)
(8533, 8534, 8535) (8785, 8786, 8787) (9213, 9214, 9215)
(9453, 9454, 9455) (9821, 9822, 9823) (9877, 9878, 9879)
 
Number of sphenic numbers < 1 000 000: 206964
Number of sphenic triplets < 1 000 000: 5457
The 200 000th sphenic number: 966467 = 17 * 139 * 409
The 5 000th sphenic triplet: (918005, 918006, 918007)
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
procedure GetSphenicNumbers(var Sphenic: TIntegerDynArray);
{Return Sphenic number up to MaxProd }
const MaxProd = 1000000;
var LimitA: integer;
var Sieve: TPrimeSieve;
var I,J,K,Prod1,Prod2: integer;
begin
Sieve:=TPrimeSieve.Create;
try
SetLength(Sphenic,0);
{Limit outer most search}
LimitA:=Trunc(CubeRoot(MaxProd));
{Sieve values up to MaxProc ~ 78,000 primes }
Sieve.Intialize(MaxProd);
{Iteratre through all combination of sequential primes}
for I:=0 to Sieve.PrimeCount-1 do
begin
{Limit first prime}
if Sieve.Primes[I]>LimitA then break;
for J:=I+1 to Sieve.PrimeCount-1 do
begin
Prod1:=Sieve.Primes[I] * Sieve.Primes[J];
{Limit product of first two primes}
if (Prod1 * Sieve.Primes[J + 1])>=MaxProd then break;
for K:=J+1 to Sieve.PrimeCount-1 do
begin
Prod2:= Prod1 * Sieve.Primes[k];
{Limit product of all three primes}
if Prod2 >=MaxProd then break;
{Store number}
SetLength(Sphenic,Length(Sphenic)+1);
Sphenic[High(Sphenic)]:=Prod2;
end;
end;
end;
finally Sieve.Free; end;
end;
 
 
 
function Compare(P1,P2: pointer): integer;
{Compare for quick sort}
begin
Result:=Integer(P1)-Integer(P2);
end;
 
{Struct to store Sphenic Triple}
 
type TSphenicTriple = record
A,B,C: integer;
end;
 
{Dynamic array to store triples}
 
type TTripletArray = array of TSphenicTriple;
 
procedure GetSphenicTriples(var Triplets: TTripletArray; var Sphenic: TIntegerDynArray);
{Get sphenic numbers and find corresponding sphenic triples}
var LS: TList;
var I,T: integer;
begin
LS:=TList.Create;
GetSphenicNumbers(Sphenic);
{Sort the numbers}
for I:=0 to High(Sphenic) do
LS.Add(Pointer(Sphenic[I]));
LS.Sort(Compare);
{Put them back in simple array}
for I:=0 to LS.Count-1 do
Sphenic[I]:=Integer(LS[I]);
SetLength(Triplets,0);
for I:=0 to High(Sphenic)-1 do
begin
T:=Sphenic[I];
{Test if the next three numbers are a triple}
if (Sphenic[I+1]=(T+1)) and (Sphenic[I+2] = (T + 2)) then
begin
{Store the result}
SetLength(Triplets,Length(Triplets)+1);
Triplets[High(Triplets)].A:=T;
Triplets[High(Triplets)].B:=T+1;
Triplets[High(Triplets)].C:=T+2;
end;
end;
end;
 
procedure SphenicTriplets(Memo: TMemo);
var Triplets: TTripletArray;
var T: TSphenicTriple;
var Sphenic: TIntegerDynArray;
var S: string;
var I: integer;
begin
{Get sphenic numbers and triples}
GetSphenicTriples(Triplets,Sphenic);
{Display sphenic numbers up to 1000}
Memo.Lines.Add('Sphenic numbers less than 1,000:');
S:='';
for I:=0 to High(Sphenic) do
begin
if Sphenic[I]>1000 then break;
S:=S+Format('%4d',[Sphenic[I]]);
if (I mod 15)=14 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
{Display sphenic triples up to a C-value of 10,000}
Memo.Lines.Add('Sphenic triples less than 10,000:');
S:='';
for I:=0 to High(Triplets) do
begin
if Triplets[I].C> 10000 then break;
S:=S+Format('[%5d %5d %5d]',[Triplets[I].A,Triplets[I].B,Triplets[I].C]);
if (I mod 3)=2 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
 
Memo.Lines.Add('Total Sphenic Numbers found = '+FloatToStrF(Sphenic[Length(Sphenic)],ffNumber,18,0));
Memo.Lines.Add(Format('Sphenic numbers < 1,000,000 = %8.0n',[Length(Sphenic)+0.0]));
Memo.Lines.Add(Format('Sphenic triplets < 1,000,000 = %8.0n',[Length(Triplets)+0.0]));
T:=Triplets[4999];
Memo.Lines.Add(Format('200,000th sphenic = %n',[Sphenic[199999]+0.0]));
Memo.Lines.Add(Format('The 5,000th triplet = %d %d %d', [T.A,T.B,T.C]));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
Sphenic numbers less than 1,000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triples less than 10,000:
[ 1309 1310 1311][ 1885 1886 1887][ 2013 2014 2015]
[ 2665 2666 2667][ 3729 3730 3731][ 5133 5134 5135]
[ 6061 6062 6063][ 6213 6214 6215][ 6305 6306 6307]
[ 6477 6478 6479][ 6853 6854 6855][ 6985 6986 6987]
[ 7257 7258 7259][ 7953 7954 7955][ 8393 8394 8395]
[ 8533 8534 8535][ 8785 8786 8787][ 9213 9214 9215]
[ 9453 9454 9455][ 9821 9822 9823][ 9877 9878 9879]
 
Total Sphenic Numbers found = 917,894
Sphenic numbers < 1,000,000 = 206,964
Sphenic triplets < 1,000,000 = 5,457
200,000th sphenic = 966,467.00
The 5,000th triplet = 918005 918006 918007
Elapsed Time: 54.572 ms.
</pre>
 
Line 811 ⟶ 1,537:
{{works with|jq}}
 
'''Generic Utilities'''
<syntaxhighlight lang=jq>
def select_while(s; cond):
Line 822 ⟶ 1,548:
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def pp($n; $width): _nwise(10$n) | map(tostring|lpad($width)) | join(" ");
</syntaxhighlight>
'''Primes'''
Line 851 ⟶ 1,577:
| length as $pc
| ($limit|cubrt|floor) as $limit2 # first prime can't be more than this
| firstlast(
label $out
foreach (range(0; $pc-2), null) as $i ({};
if| $i == null orforeach ($primes[$i] >range(0; $limit2pc-2), thennull) .emitas =$i .sphenic(null;
if $i == null or ($primes[$i] > $limit2) then break $out
else label $jout
| foreach range($i+1;else $pc-1) aslabel $j (.;jout
| foreach range($primes[$i] *+1; $primes[$j]pc-1) as $prodj (.;
| if ($prodprimes[$i] * $primes[$j + 1] >= $limit) then ., breakas $joutprod
| if ($prod * $primes[$j + 1] >= $limit) then break $jout
else label $kout
else label $kout
| foreach range($j+1; $pc) as $k (.;
| foreach range($prod *j+1; $primes[$k]pc) as $resk (.;
| if ($resprod >=* $limitprimes[$k]) then ., breakas $koutres
else .sphenic += [ | if $res] >= $limit then break $kout
else . + [$res]
end)
end)
end )) ;
select(.emit).emit )) ;
 
# Input: sphenic
Line 875 ⟶ 1,601:
| if $sphenic[$i+1] == $s + 1 and $sphenic[$i+2] == $s + 2
then . + [[$s, $s + 1, $s + 2]]
else .
end );
 
def task($limit):
(sphenic($limit)|sort) as $sphenic
| "Sphenic numbers less than 1,000:",
([select_while($sphenic[]; . < 1000)] | pp(10;3)),
"Sphenic triplets less than 10,000:",
([select_while($sphenic|triplets[] ; .[2] < 10000 )] | _nwisepp(3) | map(tostring) | join(" ";0)),
"\nThere are \($sphenic|length) sphenic numbers less than 1,000,000.",
"\nThere are \($sphenic|triplets|length) sphenic triplets less than 1,000,000.",
($sphenic[199999] as $s
| "The 200,000th sphenic number is \($s).",
"The 5,000th sphenic triplet is \($sphenic|triplets[4999])") ;
 
task(1000000)
Line 923 ⟶ 1,649:
The 200,000th sphenic number is 966467.
The 5,000th sphenic triplet is [918005,918006,918007]
</pre>
 
=={{header|Julia}}==
 
<syntaxhighlight lang=julia>
 
const SPHENIC_NUMBERS = Set{Int64}()
const NOT_SPHENIC_NUMBERS = Set{Int64}()
function issphenic(n::Int64)
n in SPHENIC_NUMBERS && return true
n in NOT_SPHENIC_NUMBERS && return false
 
nin = n
sqn = isqrt(nin)
 
npfactors = 0
isrepeat = false
 
i = 2
while n > 1 && !(npfactors == 0 && i >= sqn)
if n % i == 0
npfactors += 1
 
if isrepeat || npfactors > 3
push!(NOT_SPHENIC_NUMBERS, nin)
return false
end
 
isrepeat = true
n ÷= i
continue
end
 
i += 1
isrepeat = false
end
 
if npfactors < 3
push!(NOT_SPHENIC_NUMBERS, nin)
return false
end
 
push!(SPHENIC_NUMBERS, nin)
return true
end
 
issphenictriple(n::Integer) = issphenic(n) && issphenic(n+1) && issphenic(n+2)
printlntriple(n::Integer) = println("($(n), $(n+1), $(n+2))")
 
shenums = filter(issphenic, 2:1_000_000)
shetrip = filter(issphenictriple, 2:1_000_000)
 
# 1. All sphenic numbers less than 1,000.
println("Sphenic numbers less than 1,000:")
less1000 = filter(<(1000), shenums)
foreach(println, Iterators.partition(less1000, 15))
 
# 2. All sphenic triplets less than 10,000.
println("Sphenic triplets less than 10,000:")
less10000 = filter(<(10_000 - 6), shetrip)
foreach(printlntriple, less10000)
 
# 3. How many sphenic numbers are there less than 1 million?
println("Number of sphenic numbers that are less than 1 million: ", length(shenums))
 
# 4. How many sphenic triplets are there less than 1 million?
println("Number of sphenic triplets that are less than 1 million: ", length(shetrip))
 
# 5. What is the 200,000th sphenic number and its 3 prime factors?
println("The 200,000th sphenic number is: ", shenums[200_000])
 
# 6. What is the 5,000th sphenic triplet?
print("The 5,000h sphenic triplet is: ")
printlntriple(shetrip[5_000])
 
 
</syntaxhighlight>
 
Output:
<pre>
Sphenic numbers less than 1,000:
[30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174]
[182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285]
[286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406]
[410, 418, 426, 429, 430, 434, 435, 438, 442, 455, 465, 470, 474, 483, 494]
[498, 506, 518, 530, 534, 555, 561, 574, 582, 590, 595, 598, 602, 606, 609]
[610, 615, 618, 627, 638, 642, 645, 646, 651, 654, 658, 663, 665, 670, 678]
[682, 705, 710, 715, 730, 741, 742, 754, 759, 762, 777, 782, 786, 790, 795]
[805, 806, 814, 822, 826, 830, 834, 854, 861, 874, 885, 890, 894, 897, 902]
[903, 906, 915, 935, 938, 942, 946, 957, 962, 969, 970, 978, 986, 987, 994]
Sphenic triplets less than 10,000:
(1309, 1310, 1311)
(1885, 1886, 1887)
(2013, 2014, 2015)
(2665, 2666, 2667)
(3729, 3730, 3731)
(5133, 5134, 5135)
(6061, 6062, 6063)
(6213, 6214, 6215)
(6305, 6306, 6307)
(6477, 6478, 6479)
(6853, 6854, 6855)
(6985, 6986, 6987)
(7257, 7258, 7259)
(7953, 7954, 7955)
(8393, 8394, 8395)
(8533, 8534, 8535)
(8785, 8786, 8787)
(9213, 9214, 9215)
(9453, 9454, 9455)
(9821, 9822, 9823)
(9877, 9878, 9879)
Number of sphenic numbers that are less than 1 million: 206964
Number of sphenic triplets that are less than 1 million: 5457
The 200,000th sphenic number is: 966467
The 5,000h sphenic triplet is: (918005, 918006, 918007)
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang=Nim>import std/[algorithm, math, strformat]
 
proc initPrimes(lim: Positive): seq[int] =
## Initialize the list of prime numbers.
 
# Build a sieve of Erathostenes with only odd values.
var composite = newSeq[bool](lim div 2)
composite[0] = true
for n in countup(3, lim, 2):
if not composite[(n - 1) shr 1]:
# "n" is prime.
for k in countup(n * n, lim, 2 * n):
composite[(k - 1) shr 1] = true
 
# Build list of primes.
result = @[2]
for n in countup(3, lim, 2):
if not composite[(n - 1) shr 1]:
result.add n
 
let primes = initPrimes(500_000)
 
type
Factors = tuple[p1, p2, p3: int]
Item = tuple[sphenic: int; factors: Factors]
SphenicNumbers = seq[Item]
 
proc sphenicNumbers(lim: Positive): SphenicNumbers =
## Return a sequence of items describing sphenic numbers up to "lim".
let lim1 = cbrt(lim.toFloat).int
let lim2 = lim1 * lim1
for i1 in 0..(primes.len - 3):
let p1 = primes[i1]
if p1 >= lim1: break
for i2 in (i1 + 1)..(primes.len - 2):
let p2 = primes[i2]
let p12 = p1 * p2
if p12 >= lim2: break
for i3 in (i2 + 1)..(primes.len - 1):
let p3 = primes[i3]
let p123 = p12 * p3
if p123 >= lim: break
result.add (p123, (p1, p2, p3))
result.sort()
 
proc sphenicTriplets(sn: SphenicNumbers): seq[int] =
## Return the list of first element of sphenic triplets
## extracted from the given sequence of sphenic numbers.
for i in 0..(sn.len - 3):
let start = sn[i].sphenic
if sn[i + 1].sphenic - start == 1 and sn[i + 2].sphenic - start == 2:
result.add start
 
func tripletStr(n: Positive): string =
## Return the representation of a sphenic triplet
## described by its first element.
&"({n}, {n + 1}, {n + 2})"
 
 
echo "Sphenic numbers less than 1000:"
for i, item in sphenicNumbers(1000):
stdout.write &"{item.sphenic:5}"
if (i + 1) mod 15 == 0: echo()
 
echo "\nSphenic triplets less than 10000:"
let sn10000 = sphenicNumbers(10000)
for i, n in sphenicTriplets(sn10000):
stdout.write " ", n.tripletStr
if (i + 1) mod 3 == 0: echo()
 
let sn1000000 = sphenicNumbers(1_000_000)
echo &"\nNumber of sphenic numbers less than one million: {sn1000000.len:7}"
 
let triplets1000000 = sphenicTriplets(sn1000000)
echo &"Number of sphenic triplets less than one million: {triplets1000000.len:6}"
 
let (num, (p1, p2, p3)) = sn1000000[200_000 - 1]
echo &"\n200_000th sphenic number: {num} = {p1} * {p2} * {p3}"
 
echo &"5_000th sphenic triplet: {triplets1000000[5_000 - 1].tripletStr}"
</syntaxhighlight>
 
{{out}}
<pre>Sphenic numbers less than 1000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets less than 10000:
(1309, 1310, 1311) (1885, 1886, 1887) (2013, 2014, 2015)
(2665, 2666, 2667) (3729, 3730, 3731) (5133, 5134, 5135)
(6061, 6062, 6063) (6213, 6214, 6215) (6305, 6306, 6307)
(6477, 6478, 6479) (6853, 6854, 6855) (6985, 6986, 6987)
(7257, 7258, 7259) (7953, 7954, 7955) (8393, 8394, 8395)
(8533, 8534, 8535) (8785, 8786, 8787) (9213, 9214, 9215)
(9453, 9454, 9455) (9821, 9822, 9823) (9877, 9878, 9879)
 
Number of sphenic numbers less than one million: 206964
Number of sphenic triplets less than one million: 5457
 
200_000th sphenic number: 966467 = 17 * 139 * 409
5_000th sphenic triplet: (918005, 918006, 918007)
</pre>
 
Line 1,283 ⟶ 2,236:
real 0m4,865s user 0m4,418s sys 0m0,440s
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use List::Util 'uniq';
use ntheory qw<factor>;
 
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub table ($c, @V) { my $t = $c * (my $w = 5); ( sprintf( ('%'.$w.'d')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
 
my @sphenic = grep { my @pf = factor($_); 3 == @pf and 3 == uniq(@pf) } 1..1e6;
my @triplets = map { @sphenic[$_..$_+2] } grep { ($sphenic[$_]+2) == $sphenic[$_+2] } 0..$#sphenic-2;
 
say "Sphenic numbers less than 1,000:\n" . table 15, grep { $_ < 1000 } @sphenic;
say "Sphenic triplets less than 10,000:";
say table 3, grep { $_ < 10000 } @triplets;
 
printf "There are %s sphenic numbers less than %s\n", comma(scalar @sphenic), comma 1e6;
printf "There are %s sphenic triplets less than %s\n", comma(scalar(@triplets)/3), comma 1e6;
printf "The 200,000th sphenic number is %s\n", comma $sphenic[2e5-1];
printf "The 5,000th sphenic triplet is %s\n", join ' ', map {comma $_} @triplets[map {3*4999 + $_} 0,1,2];</syntaxhighlight>
{{out}}
<pre>Sphenic numbers less than 1,000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets less than 10,000:
1309 1310 1311
1885 1886 1887
2013 2014 2015
2665 2666 2667
3729 3730 3731
5133 5134 5135
6061 6062 6063
6213 6214 6215
6305 6306 6307
6477 6478 6479
6853 6854 6855
6985 6986 6987
7257 7258 7259
7953 7954 7955
8393 8394 8395
8533 8534 8535
8785 8786 8787
9213 9214 9215
9453 9454 9455
9821 9822 9823
9877 9878 9879
 
There are 206,964 sphenic numbers less than 1,000,000
There are 5,457 sphenic triplets less than 1,000,000
The 200,000th sphenic number is 966,467
The 5,000th sphenic triplet is 918,005 918,006 918,007</pre>
 
=={{header|Phix}}==
Line 1,602 ⟶ 2,615:
The 200,000th sphenic number is 966,467 (17 × 139 × 409).
The 5,000th sphenic triplet is (918005, 918006, 918007).</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ FACTORS
'''IF''' DUP SIZE 6 ≠ '''THEN''' DROP 0
'''ELSE''' { 0 1 0 1 0 1 } * ∑LIST 3 == '''END'''
≫ '<span style="color:blue">SPHEN?</span>' STO
≪ { } 1 1000 '''FOR''' n '''IF''' n <span style="color:blue">SPHEN?</span> '''THEN''' n + '''END NEXT'''
≫ '<span style="color:blue">TASK1</span>' STO
≪ { } 0
1 10000 '''FOR''' n
'''IF''' n <span style="color:blue">SPHEN?</span> '''THEN'''
1 +
'''IF''' DUP 3 == '''THEN''' SWAP n 2 - n 1 - n →V3 + SWAP '''END'''
'''ELSE''' DROP 0 '''END'''
'''NEXT''' DROP
≫ '<span style="color:blue">TASK2</span>' STO
{{out}}
<pre>
2: { 30 42 66 70 78 102 105 110 114 130 138 154 165 170 174 182 186 190 195 222 230 231 238 246 255 258 266 273 282 285 286 290 310 318 322 345 354 357 366 370 374 385 399 402 406 410 418 426 429 430 434 435 438 442 455 465 470 474 483 494 498 506 518 530 534 555 561 574 582 590 595 598 602 606 609 610 615 618 627 638 642 645 646 651 654 658 663 665 670 678 682 705 710 715 730 741 742 754 759 762 777 782 786 790 795 805 806 814 822 826 830 834 854 861 874 885 890 894 897 902 903 906 915 935 938 942 946 957 962 969 970 978 986 987 994 }
1: {[1309. 1310. 1311.] [1885. 1886. 1887.] [2013. 2014. 2015.] [2665. 2666. 2667.] [3729. 3730. 3731.] [5133. 5134. 5135.] [6061. 6062. 6063.] [6213. 6214. 6215.] [6305. 6306. 6307.] [6477. 6478. 6479.] [6853. 6854. 6855.] [6985. 6986. 6987.] [7257. 7258. 7259.] [7953. 7954. 7955.] [8393. 8394. 8395.] [8533. 8534. 8535.] [8785. 8786. 8787.] [9213. 9214. 9215.] [9453. 9454. 9455.] [9821. 9822. 9823.] [9877. 9878. 9879.]}
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
class Integer
def sphenic? = prime_division.map(&:last) == [1, 1, 1]
end
 
sphenics = (1..).lazy.select(&:sphenic?)
 
n = 1000
puts "Sphenic numbers less than #{n}:"
p sphenics.take_while{|s| s < n}.to_a
 
n = 10_000
puts "\nSphenic triplets less than #{n}:"
sps = sphenics.take_while{|s| s < n}.to_a
sps.each_cons(3).select{|a, b, c| a + 2 == c}.each{|ar| p ar}
 
n = 1_000_000
sphenics_below10E6 = sphenics.take_while{|s| s < n}.to_a
puts "\nThere are #{sphenics_below10E6.size} sphenic numbers below #{n}."
target = sphenics_below10E6[200_000-1]
puts "\nThe 200000th sphenic number is #{target} with factors #{target.prime_division.map(&:first)}."
triplets = sphenics_below10E6.each_cons(3).select{|a,b,c|a+2 == c}
puts "\nThe 5000th sphenic triplet is #{triplets[4999]}."</syntaxhighlight>
{{out}}
<pre>Sphenic numbers less than 1000:
[30, 42, 66, 70, 78, 102, 105, 110, 114, 130, 138, 154, 165, 170, 174, 182, 186, 190, 195, 222, 230, 231, 238, 246, 255, 258, 266, 273, 282, 285, 286, 290, 310, 318, 322, 345, 354, 357, 366, 370, 374, 385, 399, 402, 406, 410, 418, 426, 429, 430, 434, 435, 438, 442, 455, 465, 470, 474, 483, 494, 498, 506, 518, 530, 534, 555, 561, 574, 582, 590, 595, 598, 602, 606, 609, 610, 615, 618, 627, 638, 642, 645, 646, 651, 654, 658, 663, 665, 670, 678, 682, 705, 710, 715, 730, 741, 742, 754, 759, 762, 777, 782, 786, 790, 795, 805, 806, 814, 822, 826, 830, 834, 854, 861, 874, 885, 890, 894, 897, 902, 903, 906, 915, 935, 938, 942, 946, 957, 962, 969, 970, 978, 986, 987, 994]
 
Sphenic triplets less than 10000:
[1309, 1310, 1311]
[1885, 1886, 1887]
[2013, 2014, 2015]
[2665, 2666, 2667]
[3729, 3730, 3731]
[5133, 5134, 5135]
[6061, 6062, 6063]
[6213, 6214, 6215]
[6305, 6306, 6307]
[6477, 6478, 6479]
[6853, 6854, 6855]
[6985, 6986, 6987]
[7257, 7258, 7259]
[7953, 7954, 7955]
[8393, 8394, 8395]
[8533, 8534, 8535]
[8785, 8786, 8787]
[9213, 9214, 9215]
[9453, 9454, 9455]
[9821, 9822, 9823]
[9877, 9878, 9879]
 
There are 206964 sphenic numbers below 1000000.
 
The 200000th sphenic number is 966467 with factors [17, 139, 409].
 
The 5000th sphenic triplet is [918005, 918006, 918007].
</pre>
 
 
 
 
=={{header|Sidef}}==
 
<syntaxhighlight lang="ruby">func sphenic_numbers(upto) {
3.squarefree_almost_primes(upto)
}
 
func sphenic_triplets(upto) {
var S = sphenic_numbers(upto)
S.grep_kv {|k,v| v+2 == S[k+2] }.map{ [_, _+1, _+2] }
}
 
with (1e3) {|n|
say "Sphenic numbers less than #{n.commify}:"
sphenic_numbers(n-1).slices(15).each{.map{'%4s' % _}.join.say}
}
 
with (1e4) {|n|
say "\nSphenic triplets less than #{n.commify}:"
sphenic_triplets(n-1).each{.say}
}
 
with (1e6) {|n|
var triplets = sphenic_triplets(n-1)
say "\nThere are #{3.squarefree_almost_prime_count(n-1)} sphenic numbers less than #{n.commify}."
say "There are #{triplets.len} sphenic triplets less than #{n.commify}."
with (2e5) {|n| say "The #{n.commify}th sphenic number is: #{nth_squarefree_almost_prime(n, 3)}." }
with (5e3) {|n| say "The #{n.commify}th sphenic triplet is: #{triplets[n-1]}." }
}</syntaxhighlight>
 
{{out}}
<pre>
Sphenic numbers less than 1,000:
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
 
Sphenic triplets less than 10,000:
[1309, 1310, 1311]
[1885, 1886, 1887]
[2013, 2014, 2015]
[2665, 2666, 2667]
[3729, 3730, 3731]
[5133, 5134, 5135]
[6061, 6062, 6063]
[6213, 6214, 6215]
[6305, 6306, 6307]
[6477, 6478, 6479]
[6853, 6854, 6855]
[6985, 6986, 6987]
[7257, 7258, 7259]
[7953, 7954, 7955]
[8393, 8394, 8395]
[8533, 8534, 8535]
[8785, 8786, 8787]
[9213, 9214, 9215]
[9453, 9454, 9455]
[9821, 9822, 9823]
[9877, 9878, 9879]
 
There are 206964 sphenic numbers less than 1,000,000.
There are 5457 sphenic triplets less than 1,000,000.
The 200,000th sphenic number is: 966467.
The 5,000th sphenic triplet is: [918005, 918006, 918007].
</pre>
 
=={{header|Wren}}==
Line 1,608 ⟶ 2,778:
{{libheader|Wren-fmt}}
The approach here is to manufacture the sphenic numbers directly by first sieving for primes up to 1e6 / 6.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seq" for Seq
import "./fmt" for Fmt
2,122

edits