Here is a solution with identical output based on the factors routine from Count_in_factors#Raku (to be included manually until we decide where in the distribution to put it).
constant @primes = 2, |(3, 5, 7 ... *).grep: *.is-prime;multi subfactors(1) { 1 }multi subfactors(Int $remainder is copy) { gather for @primes -> $factor {# if remainder < factor², we're doneif $factor * $factor > $remainder { take $remainder if $remainder > 1;last; }# How many times can we divide by this prime?while $remainder %% $factor { take $factor;lastif ($remainder div= $factor) === 1; } }}constant @factory = lazy 0..* Z=> flat (0, 0, map { +factors($_) }, 2..*);subalmost($n) { map *.key, grep *.value == $n, @factory }put almost($_)[^10] for 1..5;