upto(n) = { res = List([2, 3]); qways = vector(n << 1); qways[4] = 1; while(res[#res] <= n, updatepos(); listput(res, nextvalue()); ); res } updatepos() = { for(i = 1, #res, qways[res[#res] + res[i]] ++ ) } nextvalue() = { for(i = res[#res] + 1, #qways, if(qways[i]==1, return(i)) ) }