Sphenic numbers

From Rosetta Code
Sphenic numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Definitions

A sphenic number is a positive integer that is the product of three distinct prime numbers. More technically it's a square-free 3-almost prime (see Related tasks below).

For the purposes of this task, a sphenic triplet is a group of three sphenic numbers which are consecutive.

Note that sphenic quadruplets are not possible because every fourth consecutive positive integer is divisible by 4 (= 2 x 2) and its prime factors would not therefore be distinct.

Examples

30 (= 2 x 3 x 5) is a sphenic number and is also clearly the first one.

[1309, 1310, 1311] is a sphenic triplet because 1309 (= 7 x 11 x 17), 1310 (= 2 x 5 x 31) and 1311 (= 3 x 19 x 23) are 3 consecutive sphenic numbers.

Task

Calculate and show here:

1. All sphenic numbers less than 1,000.

2. All sphenic triplets less than 10,000.

Stretch

3. How many sphenic numbers are there less than 1 million?

4. How many sphenic triplets are there less than 1 million?

5. What is the 200,000th sphenic number and its 3 prime factors?

6. What is the 5,000th sphenic triplet?

Hint: you only need to consider sphenic numbers less than 1 million to answer 5. and 6.

References
Related tasks


ALGOL 68[edit]

As with other samples, uses a prime sieve to construct the Sphenic numbers.

BEGIN # find some Sphenic numbers - numbers that are the product of three     #
      # distinct primes                                                       #
    PR read "primes.incl.A68" PR                    # include prime utilities #
    INT max sphenic   = 1 000 000;          # maximum number we will consider #
    INT max prime     = max sphenic OVER ( 2 * 3 );    # maximum prime needed #
    []BOOL prime      = PRIMESIEVE max prime;
    # construct a list of the primes up to the maximum prime to consider      #
    []INT  prime list = EXTRACTPRIMESUPTO max prime FROMPRIMESIEVE prime;
    # form a sieve of Sphenic numbers                                         #
    [ 1 : max sphenic ]BOOL sphenic;
    FOR i TO UPB sphenic DO sphenic[ i ] := FALSE OD;
    INT cube root max = ENTIER exp( ln( max sphenic ) / 3 );
    FOR i WHILE INT p1 = prime list[ i ];
                p1 < cube root max
    DO
        FOR j FROM i + 1 WHILE INT p2   = prime list[ j ];
                               INT p1p2 = p1 * p2;
                               ( p1p2 * p2 ) < max sphenic
        DO
            INT max p3 = max sphenic OVER p1p2;
            FOR k FROM j + 1 TO UPB prime list WHILE INT p3 = prime list[ k ];
                                                     p3 <= max p3
            DO
                sphenic[ p1p2 * p3 ] := TRUE
            OD
        OD
    OD;
    # show the Sphenic numbers up to 1 000 and triplets to 10 000             #
    print( ( "Sphenic numbers up to 1 000:", newline ) );
    INT s count := 0;
    FOR i TO 1 000 DO
        IF sphenic[ i ] THEN
            print( ( whole( i, -5 ) ) );
            IF ( s count +:= 1 ) MOD 15 = 0 THEN print( ( newline ) ) FI
        FI
    OD;
    print( ( newline ) );
    print( ( "Sphenic triplets up to 10 000:", newline ) );
    INT t count := 0;
    FOR i TO 10 000 - 2 DO
        IF sphenic[ i ] AND sphenic[ i + 1 ] AND sphenic[ i + 2 ] THEN
            print( ( "  (", whole( i,     -4 )
                   , ", ",  whole( i + 1, -4 )
                   , ", ",  whole( i + 2, -4 )
                   , ")"
                   )
                 );
            IF ( t count +:= 1 ) MOD 3 = 0 THEN print( ( newline ) ) FI
        FI
    OD;
    # count the Sphenic numbers and Sphenic triplets and find specific        #
    # Sphenic numbers and triplets                                            #
    s count := t count := 0;
    INT s200k := 0;
    INT t5k   := 0;
    FOR i TO UPB sphenic - 2 DO
        IF sphenic[ i ] THEN
            s count +:= 1;
            IF s count = 200 000 THEN
                # found the 200 000th Sphenic number                          #
                s200k := i
            FI;
            IF sphenic[ i + 1 ] AND sphenic[ i + 2 ] THEN
                t count +:= 1;
                IF t count = 5 000 THEN
                    # found the 5 000th Sphenic triplet                       #
                    t5k := i
                FI
            FI
        FI
    OD;
    FOR i FROM UPB sphenic - 1 TO UPB sphenic DO
        IF sphenic[ i ] THEN
            s count +:= 1
        FI
    OD;
    print( ( newline ) );
    print( ( "Number of Sphenic numbers  up to 1 000 000: ", whole( s count, -8 ), newline ) );
    print( ( "Number of Sphenic triplets up to 1 000 000: ", whole( t count, -8 ), newline ) );
    print( ( "The 200 000th Sphenic number:  ", whole( s200k, 0 ) ) );
    # factorise the 200 000th Sphenic number                                  #
    INT f count := 0;
    FOR i WHILE f count < 3 DO
        INT p = prime list[ i ];
        IF s200k MOD p = 0 THEN
            print( ( IF ( f count +:= 1 ) = 1 THEN ": " ELSE " * " FI
                   , whole( p, 0 )
                   )
                 )
        FI
    OD;
    print( ( newline ) );
    print( ( "The   5 000th Sphenic triplet: "
           , whole( t5k, 0 ), ", ", whole( t5k + 1, 0 ), ", ", whole( t5k + 2, 0 )
           , newline
           )
         )
END
Output:
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  up to 1 000 000:   206964
Number of Sphenic triplets up to 1 000 000:     5457
The 200 000th Sphenic number:  966467: 17 * 139 * 409
The   5 000th Sphenic triplet: 918005, 918006, 918007

AppleScript[edit]

on sieveOfEratosthenes(limit)
    set mv to missing value
    if (limit < 2) then return {}
    script o
        property numberList : prefabList(limit, mv)
    end script
    -- Write in 2, 3, and numbers which aren't their multiples.
    set o's numberList's second item to 2
    if (limit > 2) then set o's numberList's third item to 3
    repeat with n from 5 to limit by 6
        set o's numberList's item n to n
        tell (n + 2) to if (it  limit) then set o's numberList's item it to it
    end repeat
    -- "Cross out" slots for multiples of written-in numbers not then crossed out themselves.
    repeat with n from 5 to ((limit ^ 0.5) div 1) by 6
        repeat 2 times
            if (o's numberList's item n = n) then
                repeat with multiple from (n * n) to limit by n
                    set item multiple of o's numberList to mv
                end repeat
            end if
            set n to n + 2
        end repeat
    end repeat
    return o's numberList's numbers
end sieveOfEratosthenes

on prefabList(|size|, filler)
	if (|size| < 1) then return {}
	script o
		property lst : {filler}
	end script
	
	set |count| to 1
	repeat until (|count| + |count| > |size|)
		set o's lst to o's lst & o's lst
		set |count| to |count| + |count|
	end repeat
	if (|count| < |size|) then set o's lst to o's lst & o's lst's items 1 thru (|size| - |count|)
	return o's lst
end prefabList

on getSphenicsBelow(limit)
	set limit to limit - 1
	script o
		property primes : sieveOfEratosthenes(limit div (2 * 3))
		property sphenics : prefabList(limit, missing value)
	end script
	
	repeat with a from 3 to (count o's primes)
		set x to o's primes's item a
		repeat with b from 2 to (a - 1)
			set y to x * (o's primes's item b)
			if (y  limit) then exit repeat
			repeat with c from 1 to (b - 1)
				set z to y * (o's primes's item c)
				if (z > limit) then exit repeat
				set o's sphenics's item z to z
			end repeat
		end repeat
	end repeat
	return (o's sphenics's numbers)
end getSphenicsBelow

on join(lst, delim)
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to delim
	set txt to lst as text
	set AppleScript's text item delimiters to astid
	return txt
end join

on primeFactors(n)
	set output to {}
	if (n < 2) then return output
	set limit to (n ^ 0.5) div 1
	set f to 2
	repeat until (f > limit)
		if (n mod f = 0) then
			set end of output to f
			set n to n div f
			repeat while (n mod f = 0)
				set n to n div f
			end repeat
			if (limit > n) then set limit to n
		end if
		set f to f + 1
	end repeat
	if (limit < n) then set end of output to n
	return output
end primeFactors

on task()
	script o
		property sphenics : getSphenicsBelow(1000000)
	end script
	set {t1, t2, t3, t4, t5} to {{}, {}, count o's sphenics, 0, o's sphenics's 200000th item}
	repeat with i from 1 to (t3 - 2)
		set s to o's sphenics's item i
		if (s < 1000) then set end of t1 to text -4 thru -1 of ("   " & s)
		set s2 to o's sphenics's item (i + 2)
		if (s2 - s = 2) then
			if (s2 < 10000) then ¬
				set end of t2 to "{" & join(o's sphenics's items i thru (i + 2), ", ") & "}"
			set t4 to t4 + 1
			if (t4 = 5000) then ¬
				set t6 to "{" & join(o's sphenics's items i thru (i + 2), ", ") & "}"
		end if
	end repeat
	
	set output to {"Sphenic numbers < 1,000:"}
	repeat with i from 1 to 135 by 15
		set end of output to join(t1's items i thru (i + 14), "")
	end repeat
	set end of output to linefeed & "Sphenic triplets < 10,000:"
	repeat with i from 1 to 21 by 3
		set end of output to join(t2's items i thru (i + 2), " ")
	end repeat
	set end of output to linefeed & "There are " & t3 & " sphenic numbers < 1,000,000"
	set end of output to "There are " & t4 & " sphenic triplets < 1,000,000"
	set end of output to "The 200,000th sphenic number is " & t5 & ¬
		(" (" & join(primeFactors(t5), " * ") & ")")
	set end of output to "The 5,000th sphenic triplet is " & t6
	
	return join(output, linefeed)
end task

task()
Output:
"Sphenic numbers < 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 < 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 < 1,000,000
There are 5457 sphenic triplets < 1,000,000
The 200,000th sphenic number is 966467 (17 * 139 * 409)
The 5,000th sphenic triplet is {918005, 918006, 918007}"

C++[edit]

#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>

std::vector<bool> prime_sieve(int limit) {
    std::vector<bool> sieve(limit, true);
    if (limit > 0)
        sieve[0] = false;
    if (limit > 1)
        sieve[1] = false;
    for (int i = 4; i < limit; i += 2)
        sieve[i] = false;
    for (int p = 3, sq = 9; sq < limit; p += 2) {
        if (sieve[p]) {
            for (int q = sq; q < limit; q += p << 1)
                sieve[q] = false;
        }
        sq += (p + 1) << 2;
    }
    return sieve;
}

std::vector<int> prime_factors(int n) {
    std::vector<int> factors;
    if (n > 1 && (n & 1) == 0) {
        factors.push_back(2);
        while ((n & 1) == 0)
            n >>= 1;
    }
    for (int p = 3; p * p <= n; p += 2) {
        if (n % p == 0) {
            factors.push_back(p);
            while (n % p == 0)
                n /= p;
        }
    }
    if (n > 1)
        factors.push_back(n);
    return factors;
}

int main() {
    const int limit = 1000000;
    std::vector<bool> sieve = prime_sieve(limit / 6);
    std::vector<bool> sphenic(limit + 1, false);
    for (int i = 0; i < sieve.size(); ++i) {
        if (!sieve[i])
            continue;
        int jmax = limit / (i * i);
        if (jmax <= i)
            break;
        for (int j = i + 1; j <= jmax; ++j) {
            if (!sieve[j])
                continue;
            int p = i * j;
            int kmax = limit / p;
            if (kmax <= j)
                break;
            for (int k = j + 1; k <= kmax; ++k) {
                if (!sieve[k])
                    continue;
                assert(p * k <= limit);
                sphenic[p * k] = true;
            }
        }
    }

    std::cout << "Sphenic numbers < 1000:\n";
    for (int i = 0, n = 0; i < 1000; ++i) {
        if (!sphenic[i])
            continue;
        ++n;
        std::cout << std::setw(3) << i << (n % 15 == 0 ? '\n' : ' ');
    }

    std::cout << "\nSphenic triplets < 10,000:\n";
    for (int i = 0, n = 0; i < 10000; ++i) {
        if (i > 1 && sphenic[i] && sphenic[i - 1] && sphenic[i - 2]) {
            ++n;
            std::cout << "(" << i - 2 << ", " << i - 1 << ", " << i << ")"
                      << (n % 3 == 0 ? '\n' : ' ');
        }
    }

    int count = 0, triplets = 0, s200000 = 0, t5000 = 0;
    for (int i = 0; i < limit; ++i) {
        if (!sphenic[i])
            continue;
        ++count;
        if (count == 200000)
            s200000 = i;
        if (i > 1 && sphenic[i - 1] && sphenic[i - 2]) {
            ++triplets;
            if (triplets == 5000)
                t5000 = i;
        }
    }

    std::cout << "\nNumber of sphenic numbers < 1,000,000: " << count << '\n';
    std::cout << "Number of sphenic triplets < 1,000,000: " << triplets << '\n';

    auto factors = prime_factors(s200000);
    assert(factors.size() == 3);
    std::cout << "The 200,000th sphenic number: " << s200000 << " = "
              << factors[0] << " * " << factors[1] << " * " << factors[2]
              << '\n';

    std::cout << "The 5,000th sphenic triplet: (" << t5000 - 2 << ", "
              << t5000 - 1 << ", " << t5000 << ")\n";
}
Output:
Sphenic numbers < 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 < 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)

F#[edit]

This task uses Extensible Prime Generator (F#)

// Sphenic numbers. Nigel Galloway: January 23rd., 2023
let item n=Seq.item n pCache 
let triplets n=n|>Seq.windowed 3|>Seq.filter(fun n->let g=fst n[0] in g+1=fst n[1] && g+2=fst n[2])
let sphenic()=let sN=System.Collections.Generic.SortedList<int,(char*int*int*int)>()
              let next()=let n=(sN.GetKeyAtIndex 0,sN.GetValueAtIndex 0) in sN.RemoveAt 0; n
              let add f n g l=sN.Add((item n)*item(g)*(item l),(f,n,g,l))
              let rec fN g=seq{match g with (y,('n',n,g,l))->yield (y,(n,g,l)); add 'n' (n+1) (g+1) (l+1); add 'l' n (g+1) (l+1); add 'g' n g (l+1); yield! fN(next())
                                           |(y,('g',n,g,l))->yield (y,(n,g,l)); add 'g' n g (l+1); yield! fN(next())
                                           |(y,('l',n,g,l))->yield (y,(n,g,l)); add 'l' n (g+1) (l+1); add 'g' n g (l+1); yield! fN(next())}
              fN(30,('n',0,1,2))
sphenic()|>Seq.takeWhile(fun(n,_)->n<1000)|>Seq.iter(fun(n,_)->printf "%d " n); printfn ""
sphenic()|>Seq.takeWhile(fun(n,_)->n<10000)|>triplets|>Seq.iter(fun n->printfn "%d %d %d" (fst n[0]) (fst n[1]) (fst n[2]))
printfn $"There are %d{sphenic()|>Seq.takeWhile(fun(n,_)->n<1000000)|>Seq.length} sphenic numbers less than 1 million"
printfn $"There are %d{sphenic()|>Seq.takeWhile(fun(n,_)->n<1000000)|>triplets|>Seq.length} sphenic triplets less than 1 million"
let y,(n,g,l)=sphenic()|>Seq.item 199999 in printfn "The 200,000th sphenic number is %d (%d %d %d)" y (item n) (item g) (item l)
let n=sphenic()|>triplets|>Seq.item 4999 in printfn "The 5,000th sphenic triplet is %d %d %d" (fst n[0]) (fst n[1]) (fst n[2])
Output:
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
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 million
There are 5457 sphenic triplets less than 1 million
The 200,000th sphenic number is 966467 (17 139 409)
The 5,000th sphenic triplet is 918005 918006 918007

Go[edit]

Translation of: Wren
Library: Go-rcu
package main

import (
    "fmt"
    "math"
    "rcu"
    "sort"
)

func main() {
    const limit = 1000000
    limit2 := int(math.Cbrt(limit)) 
    primes := rcu.Primes(limit / 6)
    pc := len(primes)
    var sphenic []int
    fmt.Println("Sphenic numbers less than 1,000:")
    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 = append(sphenic, res)
            }
        }
    }
    sort.Ints(sphenic)
    ix := sort.Search(len(sphenic), func(i int) bool { return sphenic[i] >= 1000 })
    rcu.PrintTable(sphenic[:ix], 15, 3, false)
    fmt.Println("\nSphenic triplets less than 10,000:")
    var triplets [][3]int
    for i := 0; i < len(sphenic)-2; i++ {
        s := sphenic[i]
        if sphenic[i+1] == s+1 && sphenic[i+2] == s+2 {
            triplets = append(triplets, [3]int{s, s + 1, s + 2})
        }
    }
    ix = sort.Search(len(triplets), func(i int) bool { return triplets[i][2] >= 10000 })
    for i := 0; i < ix; i++ {
        fmt.Printf("%4d ", triplets[i])
        if (i+1)%3 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\nThere are %s sphenic numbers less than 1,000,000.\n", rcu.Commatize(len(sphenic)))
    fmt.Printf("There are %s sphenic triplets less than 1,000,000.\n", rcu.Commatize(len(triplets)))
    s := sphenic[199999]
    pf := rcu.PrimeFactors(s)
    fmt.Printf("The 200,000th sphenic number is %s (%d*%d*%d).\n", rcu.Commatize(s), pf[0], pf[1], pf[2])
    fmt.Printf("The 5,000th sphenic triplet is %v.\n.", triplets[4999])
}
Output:
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].

J[edit]

Implementation:

sphenic=: {{ N #~ N = {{*/~.3{.y}}@q: N=. 30}.i.y }}
triplet=: {{ 0 1 2 +/~y #~ */y e.~ 0 1 2 +/ y }}

Here, sphenic gives all sphenic numbers up through its right argument, and triplet returns sequences of three adjacent numbers from its right argument.

Task examples:

   9 15$sphenic 1e3
 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
   triplet sphenic 1e4
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
   # sphenic 1e6
206964
   # triplet sphenic 1e6
5457
   4999 { triplet sphenic 1e6   NB. 0 is first
918005 918006 918007

Pascal[edit]

Free Pascal[edit]

Translation of: Wren
Output Format
Translation of: AppleScript

Most of the time, ~ 75% in this case, is spent with sort. Now changed to use sieve of erathostenes and insert sphenic numbers in that array,So no sort is needed. A little bit lengthy.
TIO.RUN uses a 2.3 Ghz Intel Chip (XEON? ) and hates big allocations. 1E9 extreme slow.

program sphenic;
{$IFDEF FPC}{$MODE DELPHI}{$Optimization ON,ALL}{$CODEALIGn proc=16}{$ENDIF}
{$IFDEF WINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
const
  Limit= 1000*1000;

type
  tPrimesSieve = array of boolean;
  tElement = Uint32;
  tarrElement = array of tElement;
  tpPrimes = pBoolean;

var
  PrimeSieve : tPrimesSieve;
  primes : tarrElement;
  sphenics : tarrElement;
  procedure ClearAll;
  begin
    setlength(sphenics,0);
    setlength(primes,0);
    setlength(PrimeSieve,0);
  end;
  function BuildWheel(pPrimes:tpPrimes;lmt:Uint32): longint;
  var
    wheelSize, wpno, pr, pw, i, k: NativeUint;
    wheelprimes: array[0..15] of byte;
  begin
    pr := 1;//the mother of all numbers 1 ;-)
    pPrimes[1] := True;
    WheelSize := 1;

    wpno := 0;
    repeat
      Inc(pr);
      //pw = pr projected in wheel of wheelsize
      pw := pr;
      if pw > wheelsize then
        Dec(pw, wheelsize);
      if pPrimes[pw] then
      begin
        k := WheelSize + 1;
        //turn the wheel (pr-1)-times
        for i := 1 to pr - 1 do
        begin
          Inc(k, WheelSize);
          if k < lmt then
            move(pPrimes[1], pPrimes[k - WheelSize], WheelSize)
          else
          begin
            move(pPrimes[1], pPrimes[k - WheelSize], Lmt - WheelSize * i);
            break;
          end;
        end;
        Dec(k);
        if k > lmt then
          k := lmt;
        wheelPrimes[wpno] := pr;
        pPrimes[pr] := False;
        Inc(wpno);

        WheelSize := k;//the new wheelsize
        //sieve multiples of the new found prime
        i := pr;
        i := i * i;
        while i <= k do
        begin
          pPrimes[i] := False;
          Inc(i, pr);
        end;
      end;
    until WheelSize >= lmt;

    //re-insert wheel-primes 1 still stays prime
    while wpno > 0 do
    begin
      Dec(wpno);
      pPrimes[wheelPrimes[wpno]] := True;
    end;
    result := pr;
  end;

  procedure Sieve(pPrimes:tpPrimes;lmt:Uint32);
  var
    sieveprime, fakt, i: UInt32;
  begin
    sieveprime := BuildWheel(pPrimes,lmt);
    repeat
      repeat
        Inc(sieveprime);
      until pPrimes[sieveprime];
      fakt := Lmt div sieveprime;
      while Not(pPrimes[fakt]) do
        dec(fakt);
      if fakt < sieveprime then
        BREAK;
      i := (fakt + 1) mod 6;
      if i = 0 then
        i := 4;
      repeat
        pPrimes[sieveprime * fakt] := False;
        repeat
          Dec(fakt, i);
          i := 6 - i;
        until pPrimes[fakt];
        if fakt < sieveprime then
          BREAK;
      until False;
    until False;
    pPrimes[1] := False;//remove 1
  end;

procedure InitAndGetPrimes;
var
  prCnt,i,lmt : UInt32;
begin
  setlength(PrimeSieve,Limit+1);// inits with #0
  lmt := Limit DIV (2*3);
  if Lmt < 65536 then
    setlength(Primes,6542)
  else
    setlength(Primes,trunc(lmt/(ln(lmt)-1.1)));
  Sieve(@PrimeSieve[0],lmt);
  prCnt := 0;
  for i := 1 to Lmt do
  Begin
    if PrimeSieve[i] then
    begin
      primes[prCnt] := i;
      inc(prCnt);
    end;
  end;
  setlength(primes,prCnt);
  // clear used by sieving section
  fillchar(PrimeSieve[0],Lmt+1,#0);
end;

function binary_search(value: Uint32;const A:tarrElement): Int32;
var
  p : Uint32;
  l, m, h: tElement;
begin
  l := Low(primes);
  h := High(primes);
  while l <= h do
  begin
    m := (l + h) div 2;
    p := A[m];
    if p > value then
    begin
      h := m - 1;
    end
    else
    begin
      if p < value then
      begin
        l := m + 1;
      end
      else
        exit(m);
    end;
  end;
  binary_search:=m;
end;

procedure CreateSphenics(const pr:tarrElement);
var
  i1,i2,i3,
  idx1,idx2,
  p1,p2,p,cnt : Uint32;
begin
  cnt := 0;
  p := trunc(exp(1/3*ln(Limit)));
  idx1 := binary_search(p,Pr)-1;
  i1 := 0;
  repeat
    p1 := pr[i1];
    p := trunc(sqrt(Limit DIV p1));
    idx2:= binary_search(p,Pr)+1;
    For i2 := i1+1 to idx2 do
    begin
      p2:= pr[i2]*p1;
      For i3 := i2+1 to High(pr) do
      begin
        p := Pr[i3]*p2;
        if p > Limit then
          break;
        //mark as sphenic number
        PrimeSieve[p]:= true;
        inc(cnt);
      end;
    end;
    inc(i1);
  until i1>idx1;
  //insert
  setlength(sphenics,cnt);
  p := 0;
  For i1 := 0 to Limit do
  begin
    if PrimeSieve[i1] then
    begin
      sphenics[p] := i1;
      inc(p);
    end;
  end;
end;

//alternativ with less variables, needs fast mul of CPU
(*
procedure CreateSphenics(const pr:tarrElement);
var
  cnt,i1,i2,i3,
  p1,p2,p : Uint32;
begin
  cnt := 0;
  i1 :=0;
  repeat
    p1 := Pr[i1];
    if p1*p1*p1 > Limit then
      BREAK;
    i2 := i1+1;
    repeat
      p := Pr[i2];
      if (p*p)*p1 > Limit then
        BREAK;
      p2:= p1*p;
      For i3 := i2+1 to High(Pr) do
      begin
        p := Pr[i3]*p2;
        if p > LIMIT then
          BREAK;
        PrimeSieve[p]:= true;
        inc(cnt);
      end;
      inc(i2)
    until false;
    inc(i1);
  until false;
  //insert
  setlength(sphenics,cnt);
  p := 0;
  For i1 := 0 to Limit do
  begin
    if PrimeSieve[i1] then
    begin
      sphenics[p] := i1;
      inc(p);
    end;
  end;
end;
*)

procedure OutTriplet(i:Uint32);
begin
  write('{',sphenics[i],',',sphenics[i+1],',',sphenics[i+2],'}');
end;

function CheckTriplets(i:Uint32):boolean;inline;
begin
  CheckTriplets:= PrimeSieve[i] AND PrimeSieve[i+1] AND PrimeSieve[i+2];
end;

var
  i,j,t5000 : Uint32;
begin
  InitAndGetPrimes;
  CreateSphenics(Primes);
  writeln('Sphenic numbers < 1,000:');
  i := 0;
  repeat
    if sphenics[i] > 1000 then
      break;
    write(sphenics[i]:4);
    inc(i);
    if i Mod 15 = 0 then
      writeln;
  until i>= High(sphenics);
  writeln;
  writeln('Sphenic triplets < 10,000:');
  i := 0;
  j := 0;
  repeat
    if CheckTriplets(sphenics[i]) then
    Begin
      OutTriplet(i);
      inc(j);
      if j < 3 then
        write(',')
      else
      begin
        writeln;
        j := 0;
      end;
    end;
    inc(i);
  until sphenics[i+2]>10000;
  writeln;
  i := 0;
  j := 0;
  writeln('There are ',length(sphenics),' sphenic numbers < ',limit);
  repeat
    if CheckTriplets(sphenics[i]) then
    Begin
       inc(j);
       if j = 5000 then
         t5000 := i;
    end;
    inc(i);
  until i+2 >high(sphenics);
  writeln('There are ',j,' sphenic triplets numbers < ',limit);
  writeln('The 200,000th sphenic number is ',sphenics[200000-1]);
  write('The 5,000th sphenic triplet is ');OutTriplet(T5000);
  ClearAll;
end.
@TIO.RUN:
Sphenic numbers < 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 < 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 < 1000000
There are 5457 sphenic triplets numbers < 1000000
The 200,000th sphenic number is 966467
The 5,000th sphenic triplet is {918005,918006,918007}
Real time: 0.096 s User time: 0.067 s Sys. time: 0.028 s

@home (4.4 Ghz Ryzen 5600G):
There are 2086746 sphenic numbers < 10000000
There are 20710806 sphenic numbers < 100000000
There are 203834084 sphenic numbers < 1000000000

There are 55576 sphenic triplets numbers < 10000000
There are 527138 sphenic triplets numbers < 100000000
There are 4824694 sphenic triplets numbers < 1000000000
real	0m4,865s user	0m4,418s sys	0m0,440s

Phix[edit]

Translation of: Wren
with javascript_semantics
function get_sphenic(integer limit)
    sequence sphenic = {},
             primes = get_primes_le(floor(limit/6))
    integer pc = length(primes)
    for i=1 to pc-2 do
        for j=i+1 to pc-1 do
            atom prod = primes[i]*primes[j]
            if prod*primes[j+1]>=limit then exit end if
            for k=j+1 to pc do
                atom res = prod*primes[k]
                if res>=limit then exit end if
                sphenic &= res
            end for
        end for
    end for
    sphenic = sort(sphenic)
    return sphenic
end function
sequence sphenic = get_sphenic(1000000)
printf(1,"Sphenic numbers less than 1,000:\n")
printf(1,"%s\n",join_by(filter(sphenic,"<",1000),1,15," ",fmt:="%3d"))
printf(1,"Sphenic triplets less than 10,000:\n")
sequence triplets = {}
for i=1 to length(sphenic)-2 do
    atom s = sphenic[i]
    if sphenic[i+1]==s+1 
    and sphenic[i+2]==s+2 then
        triplets = append(triplets,{s,s+1,s+2})
    end if
end for
function tltk(sequence t) return t[3]<10000 end function
printf(1,"%s\n",join_by(apply(filter(triplets,tltk),sprint),1,3," "))
printf(1,"There are %,d sphenic numbers less than 1,000,000.\n",length(sphenic))
printf(1,"There are %,d sphenic triplets less than 1,000,000.\n",length(triplets))
atom s = sphenic[200000]
string f = join(prime_factors(s),"*",fmt:="%d")
printf(1,"The 200,000th sphenic number is %,d (%s).\n", {s, f})
printf(1,"The 5,000th sphenic triplet is %v.\n", {triplets[5000]})
Output:
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}.

PL/M[edit]

Works with: 8080 PL/M Compiler
... under CP/M (or an emulator)

Basic task only as the 8080 PL/M compiler only supports unsigned 8 and 16 bit integers.
Based on the Algol 68 sample.

100H: /* FIND SOME SPHENIC NUMBERS - NUMBERS THAT ARE THE PRODUCT OF THREE   */
      /* DISTINCT PRIMES                                                     */

   /* CP/M BDOS SYSTEM CALLS AND I/O ROUTINES                                */
   BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5;  END;
   PR$CHAR:    PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C );     END;
   PR$STRING:  PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S );  END;
   PR$NL:      PROCEDURE;   CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
   PR$NUMBER4: PROCEDURE( N );
      DECLARE N ADDRESS;
      DECLARE V ADDRESS, N$STR( 6 ) BYTE, W BYTE;
      V = N;
      W = LAST( N$STR );
      N$STR( W ) = '$';
      N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
      DO WHILE( ( V := V / 10 ) > 0 );
         N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
      END;
      DO WHILE W > 1;
         N$STR( W := W - 1 ) = ' ';
      END;
      CALL PR$STRING( .N$STR( W ) );
   END PR$NUMBER4;

   /* TASK                                                                   */

   DECLARE MAX$SPHENIC   LITERALLY '10$000'; /* MAX NUMBER WE WILL CONSIDER  */
   DECLARE DCL$SPHENIC   LITERALLY '10$001'; /* FOR ARRAY DECLARATION        */
   DECLARE CUBE$ROOT$MAX LITERALLY '22';     /* APPROX CUBE ROOT OF MAX      */
   DECLARE MAX$PRIME     LITERALLY '1667';   /* MAX PRIME NEEDED (10000/2/3) */
   DECLARE DCL$PRIME     LITERALLY '1668';   /* FOR ARRAY DECLARATION        */
   DECLARE SQ$ROOT$MAX   LITERALLY '41';     /* APPROX SQ ROOT OF MAX$PRIME  */
   DECLARE FALSE         LITERALLY '0';
   DECLARE TRUE          LITERALLY '1';
   DECLARE ( I, J, K, P1, P2, P3, P1P2, MAX$P3, COUNT ) ADDRESS;

   /* SIEVE THE PRIMES TO MAX$PRIME                                          */
   DECLARE PRIME ( DCL$PRIME )BYTE;
   PRIME( 0 ), PRIME( 1 ) = FALSE; PRIME( 2 ) = TRUE;
   DO I = 3 TO LAST( PRIME ) BY 2; PRIME( I ) = TRUE;  END;
   DO I = 4 TO LAST( PRIME ) BY 2; PRIME( I ) = FALSE; END;
   DO I = 3 TO SQ$ROOT$MAX;
      IF PRIME( I ) THEN DO;
         DO J = I * I TO LAST( PRIME ) BY I + I; PRIME( J ) = FALSE; END;
      END;
   END;

   /* SIEVE THE SPHENIC NUMBERS TO MAX$SPHENIC                               */
   DECLARE SPHENIC ( DCL$SPHENIC )BYTE;
   NEXT$PRIME: PROCEDURE( P$PTR )ADDRESS; /* RETURNS THE NEXT PRIME AFTER P  */
      DECLARE P$PTR         ADDRESS;      /* AND SETS P TO IT                */
      DECLARE P BASED P$PTR ADDRESS;
      DECLARE FOUND         BYTE;
      FOUND = PRIME( P := P + 1 );
      DO WHILE P < LAST( PRIME ) AND NOT FOUND;
         FOUND = PRIME( P := P + 1 );
      END;
      RETURN P;
   END NEXT$PRIME;
   DO I = 0 TO LAST( SPHENIC ); SPHENIC( I ) = FALSE; END;
   I = 0;
   DO WHILE ( P1 := NEXT$PRIME( .I ) ) < CUBE$ROOT$MAX;
      J = I;
      DO WHILE ( P1P2 := P1 * ( P2 := NEXT$PRIME( .J ) ) ) < MAX$SPHENIC;
         MAX$P3 = MAX$SPHENIC / P1P2;
         K = J;
         DO WHILE ( P3 := NEXT$PRIME( .K ) ) <= MAX$P3;
            SPHENIC( P1P2 * P3 ) = TRUE;
         END;
      END;
   END;

   /* SHOW THE SPHENIC NUMBERS UP TO 1 000 AND TRIPLETS TO 10 000            */
   CALL PR$STRING( .'SPHENIC NUMBERS UP TO 1 000:$' );CALL PR$NL;
   COUNT = 0;
   DO I = 1 TO 1$000;
      IF SPHENIC( I ) THEN DO;
         CALL PR$CHAR( ' ' );CALL PR$NUMBER4( I );
         IF ( COUNT := COUNT + 1 ) MOD 15 = 0 THEN CALL PR$NL;
      END;
   END;
   CALL PR$NL;
   CALL PR$STRING( .'SPHENIC TRIPLETS UP TO 10 000:$' );CALL PR$NL;
   COUNT = 0;
   DO I = 1 TO 10$000 - 2;
      IF SPHENIC( I ) AND SPHENIC( I + 1 ) AND SPHENIC( I + 2 ) THEN DO;
         CALL PR$STRING( .'  ($' );CALL PR$NUMBER4( I     );
         CALL PR$STRING(  .', $' );CALL PR$NUMBER4( I + 1 );
         CALL PR$STRING(  .', $' );CALL PR$NUMBER4( I + 2 );
         CALL PR$CHAR( ')' );
         IF ( COUNT := COUNT + 1 ) MOD 3 = 0 THEN CALL PR$NL;
      END;
   END;

EOF
Output:
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)

Python[edit]

""" rosettacode.org task Sphenic_numbers """


from sympy import factorint

sphenics1m, sphenic_triplets1m = [], []

for i in range(3, 1_000_000):
    d = factorint(i)
    if len(d) == 3 and sum(d.values()) == 3:
        sphenics1m.append(i)
        if len(sphenics1m) > 2 and i - sphenics1m[-3] == 2 and i - sphenics1m[-2] == 1:
            sphenic_triplets1m.append(i)

print('Sphenic numbers less than 1000:')
for i, n in enumerate(sphenics1m):
    if n < 1000:
        print(f'{n : 5}', end='\n' if (i + 1) % 15 == 0 else '')
    else:
        break

print('\n\nSphenic triplets less than 10_000:')
for i, n in enumerate(sphenic_triplets1m):
    if n < 10_000:
        print(f'({n - 2} {n - 1} {n})', end='\n' if (i + 1) % 3 == 0 else '  ')
    else:
        break

print('\nThere are', len(sphenics1m), 'sphenic numbers and', len(sphenic_triplets1m),
      'sphenic triplets less than 1 million.')

S2HK = sphenics1m[200_000 - 1]
T5K = sphenic_triplets1m[5000 - 1]
print(f'The 200_000th sphenic number is {S2HK}, with prime factors {list(factorint(S2HK).keys())}.')
print(f'The 5000th sphenic triplet is ({T5K - 2} {T5K - 1} {T5K}).')
Output:
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 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 and 5457 sphenic triplets less than 1 million.
The 200_000th sphenic number is 966467, with prime factors [17, 139, 409].
The 5000th sphenic triplet is (918005 918006 918007).

Raku[edit]

Not the most efficient algorithm, but massively parallelizable, so finishes pretty quickly.

use Prime::Factor;
use List::Divvy;
use Lingua::EN::Numbers;

my @sphenic = lazy (^Inf).hyper(:200batch).grep: { my @pf = .&prime-factors; +@pf == 3 and +@pf.unique == 3 };
my @triplets = lazy (^Inf).grep( { @sphenic[$_] + 2 == @sphenic[$_ + 2] } )\
              .map: {(@sphenic[$_],@sphenic[$_+1],@sphenic[$_+2])}

say "Sphenic numbers less than 1,000:\n" ~
    @sphenic.&upto(1e3).batch(15)».fmt("%3d").join: "\n";

say "\nSphenic triplets less than 10,000:";
.say for @triplets.&before(*.[2] > 1e4);

say "\nThere are {(+@sphenic.&upto(1e6)).&comma} sphenic numbers less than {1e6.Int.&comma}";
say "There are {(+@triplets.&before(*.[2] > 1e6)).&comma} sphenic triplets less than {1e6.Int.&comma}";
say "The 200,000th sphenic number is {@sphenic[2e5-1].&comma} ({@sphenic[2e5-1].&prime-factors.join(' × ')}).";
say "The 5,000th sphenic triplet is ({@triplets[5e3-1].join(', ')})."
Output:
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).

Wren[edit]

Library: Wren-math
Library: Wren-seq
Library: Wren-fmt

The approach here is to manufacture the sphenic numbers directly by first sieving for primes up to 1e6 / 6.

import "./math" for Int
import "./seq" for Seq
import "./fmt" for Fmt

var limit = 1000000
var limit2 = limit.cbrt.floor // first prime can't be more than this
var primes = Int.primeSieve((limit/6).floor)
var pc = primes.count
var sphenic = []
System.print("Sphenic numbers less than 1,000:")
for (i in 0...pc-2) {
    if (primes[i] > limit2) break
    for (j in i+1...pc-1) {
        var prod = primes[i] * primes[j]
        if (prod * primes[j + 1] >= limit) break
        for (k in j+1...pc) {
            var res = prod * primes[k]
            if (res >= limit) break
            sphenic.add(res)
        }
    }
}
sphenic.sort()
Fmt.tprint("$3d", Seq.takeWhile(sphenic) { |s| s < 1000 }, 15)
System.print("\nSphenic triplets less than 10,000:")
var triplets = []
for (i in 0...sphenic.count-2) {
    var s = sphenic[i]
    if (sphenic[i+1] == s + 1 && sphenic[i+2] == s + 2) {
        triplets.add([s, s + 1, s + 2])
    }
}
Fmt.tprint("$18n", Seq.takeWhile(triplets) { |t| t[2] < 10000 }, 3)
Fmt.print("\nThere are $,d sphenic numbers less than 1,000,000.", sphenic.count)
Fmt.print("There are $,d sphenic triplets less than 1,000,000.", triplets.count)
var s = sphenic[199999]
Fmt.print("The 200,000th sphenic number is $,d ($s).", s, Int.primeFactors(s).join("*"))
Fmt.print("The 5,000th sphenic triplet is $n.", triplets[4999])
Output:
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].

XPL0[edit]

Runs in less than five seconds on Pi4.

int  Factors(3);

func Sphenic(N);        \Return 'true' if N is sphenic
int  N, C, F, L, Q;
[L:= sqrt(N);
C:= 0;  F:= 2;
loop    [Q:= N/F;
        if rem(0) = 0 then
                [Factors(C):= F;        \found a factor
                C:= C+1;                \count it
                if C > 3 then return false;
                N:= Q;
                if rem(N/F) = 0 then    \has a square
                    return false;
                if F > N then quit;
                ]
        else    [F:= F+1;
                if F > L then           \reached limit
                    [Factors(C):= N;
                    C:= C+1;
                    quit;
                    ];
                ];
        ];
return C = 3;
];

int C, N, I;
[Format(4, 0);
C:= 0;  N:= 2*3*5;
Text(0, "Sphenic numbers less than 1,000:^m^j");
loop    [if Sphenic(N) then
            [C:= C+1;
            if N < 1000 then
                [RlOut(0, float(N));
                if rem(C/15) = 0 then CrLf(0);
                ];
            if C = 200_000 then
                [Text(0, "The 200,000th sphenic number is ");
                IntOut(0, N);
                Text(0, " = ");
                for I:= 0 to 2 do
                        [IntOut(0, Factors(I));
                        if I < 2 then Text(0, "*");
                        ];
                CrLf(0);
                ];
            ];
        N:= N+1;
        if N >= 1_000_000 then quit;
        ];
Text(0, "There are ");  IntOut(0, C);
Text(0, " sphenic numbers less than 1,000,000^m^j^m^j");

C:= 0;  N:= 2*3*5;
Text(0, "Sphenic triplets less than 10,000:^m^j");
loop    [if Sphenic(N) then if Sphenic(N+1) then if Sphenic(N+2) then
            [C:= C+1;
            if N < 10_000 then
                [ChOut(0, ^[);
                for I:= 0 to 2 do
                    [IntOut(0, N+I);
                    if I < 2 then Text(0, ", ");
                    ];
                ChOut(0, ^]);
                if rem(C/3) = 0 then CrLf(0) else Text(0, ", ");;
                ];
            if C = 5000 then
                [Text(0, "The 5000th sphenic triplet is [");
                for I:= 0 to 2 do
                    [IntOut(0, N+I);
                    if I < 2 then Text(0, ", ");
                    ];
                Text(0, "]^m^j");
                ];
            ];
        N:= N+1;
        if N+2 >= 1_000_000 then quit;
        ];
Text(0, "There are ");  IntOut(0, C);
Text(0, " sphenic triplets less than 1,000,000^m^j");
]
Output:
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