(PARI) test(n)=for(p=2, 3, while(n%p==0, n/=p)); n==1;
for(n=1, 4000, if(test(n), print1(n", ")))
(PARI) list(lim)=my(v=List(), N); for(n=0, log(lim\1+.5)\log(3), N=3^n; while(N<=lim, listput(v, N); N<<=1)); vecsort(Vec(v)) \\
Charles R Greathouse IV, Jun 28 2011
(PARI) list(lim)=my(v=List(), N); for(n=0, logint(lim\=1, 3), N=3^n; while(N<=lim, listput(v, N); N<<=1)); Set(v) \\
Charles R Greathouse IV, Jan 10 2018
(Haskell)
import Data.Set (Set, singleton, insert, deleteFindMin)
smooth :: Set Integer -> [Integer]
smooth s = x : smooth (insert (3*x) $ insert (2*x) s')
where (x, s') = deleteFindMin s
a003586_list = smooth (singleton 1)
a003586 n = a003586_list !! (n-1)
(SageMath)
def isA003586(n) :
return not any(d != 2 and d != 3 for d in prime_divisors(n))
@CachedFunction
if n == 1 : return 1
while not isA003586(k) : k += 1
return k
(Python)
from itertools import count, takewhile
def aupto(lim):
pows2 = list(takewhile(lambda x: x<lim, (2**i for i in count(0))))
pows3 = list(takewhile(lambda x: x<lim, (3**i for i in count(0))))
return sorted(c*d for c in pows2 for d in pows3 if c*d <= lim)
(Python)
from sympy import integer_log
def bisection(f, kmin=0, kmax=1):
while f(kmax) > kmax: kmax <<= 1
while kmax-kmin > 1:
kmid = kmax+kmin>>1
if f(kmid) <= kmid:
kmax = kmid
else:
kmin = kmid
return kmax
def f(x): return n+x-sum((x//3**i).bit_length() for i in range(integer_log(x, 3)[0]+1))
(Python) # faster for initial segment of sequence
import heapq
from itertools import islice
def A003586gen(): # generator of terms
v, oldv, h, psmooth_primes, = 1, 0, [1], [2, 3]
while True:
v = heapq.heappop(h)
if v != oldv:
yield v
oldv = v
for p in psmooth_primes:
heapq.heappush(h, v*p)
(C++) // Returns
A003586 <= threshold without approximations nor sorting
#include <forward_list>
std::forward_list<int>
A003586(const int threshold) {
std::forward_list<int> sequence;
auto start_it = sequence.before_begin();
for (int i = 1; i <= threshold; i *= 2) {
for (int inc = 1; std::next(start_it) != sequence.end() && inc <= i; inc *= 3)
++start_it;
auto it = start_it;
for (int j = 1; i * j <= threshold; j *= 3) {
sequence.emplace_after(it, i * j);
for (int inc = 1; std::next(it) != sequence.end() && inc <= i; inc *= 2)
++it;
}
}
return sequence;
(Magma) [n: n in [1..4000] | PrimeDivisors(n) subset [2, 3]]; //
Bruno Berselli, Sep 24 2012