function [ a ] = A348268( max_n ) a = 1; p = primes(max_n); lw = lyndonwords(1); lyndonw = lw{2}; for n = 2:18 lyndonw =[lyndonw lyndonwords(n)]; end for n = 1:max_n o = 1; wraw = bitget(n,1:32); word = wraw(1:find(wraw == 1, 1, 'last' )); factorlist = lyndonfactor( word ); for m = 1:length(factorlist) o = o*p(findcell(lyndonw,factorlist{m})); end a(n+1) = o; end end function i = findcell(carray,word) i = 0; for n = 1:length(carray) if length(carray{n}) == length(word) if carray{n} == word i = n; end end end end function words = lyndonwords(maxlen) words = cell(1); wordindex = 1; w = 0; while ~isempty(w) len = length(w); if(len == maxlen) s = []; for j = 1:length(w) s = [s w(j)]; end words{wordindex} = s; wordindex = wordindex + 1; else while length(w) < maxlen w = [w w(1+length(w)-len)]; end end while ~isempty(w) && w(end) == 1 w = w(1:end-1); end if ~isempty(w) w(end) = 1; end end end function [ factorlist ] = lyndonfactor( inputword ) factorlist = cell(1); old = 1; startlist = lyndonstart( inputword ); for n = 1:length(startlist) factorlist{n} = inputword(old:startlist(n)-1); old = startlist(n); end end function [ startlist ] = lyndonstart( inputword ) lenw = length(inputword); k = 1; r = 1; startlist = []; while k <= lenw i = k; j = k+1; while j <= lenw && inputword(i) <= inputword(j) if inputword(i) == inputword(j) i = i+1; else i = k; end j = j+1; end while k < i+1; k = k + j - i; startlist = [startlist k]; end end end