OFFSET
1,1
COMMENTS
Start with the sequence of the nonprime numbers. For visual clarity, it is interrupted with spaces where the primes are missing, and the nonprimes or their groups in the prime gaps are distinct:
1 4 6 8 9 10 12 14 15 16 18 20 21 22 ...
Replace the first nonprime 1 with the first prime 2 and thereafter every single or every first nonprime in the prime gaps with successive primes:
2 3 5 7 9 10 11 13 15 16 17 19 21 22 ...
Next, replace every second nonprime in the prime gaps with a new sequence of the primes:
2 3 5 7 2 10 11 13 3 16 17 19 5 22 ...
Follow by replacing every third nonprime in the prime gaps with yet another prime sequence:
2 3 5 7 2 2 11 13 3 3 17 19 5 5 ...
And so on. The sums of the substituting primes in the individual prime gaps form the terms of the sequence:
2 3 5 11 11 19 17 29 ...
PROG
(MATLAB)
function a = A354400( max_prime )
% fill the gaps
p = primes(max_prime); b = [1:max_prime];
b(isprime(b) == 0) = 0;
pj = [0 find(b > 0)]; pjo = pj;
j = pj(b(pj+1) == 0)+1;
while ~isempty(j)
b(j) = p(1:length(j));
pj = find(b(1:end-1) > 0);
if ~isempty(find(b == 0, 1))
j = pj(b(pj+1) == 0)+1;
else
j = [];
end
end
% sum the gaps
k = 1;
for n = 1:length(pjo)-1
m = sum(b(pjo(n)+1:pjo(n+1)-1));
if m > 0
a(k) = m; k = k+1;
end
end
end % Thomas Scheuerle, May 25 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Tamas Sandor Nagy, May 25 2022
STATUS
approved