login
a(n) = a(n-1) + a(n - 1 minus the number of terms of a(k) == n (mod 3) so far).
0

%I #5 Dec 20 2022 22:50:06

%S 1,2,3,5,7,12,17,22,34,41,53,87,109,131,184,218,252,361,414,501,632,

%T 763,894,1112,1330,1548,1909,2161,2575,3207,3568,4331,5225,5726,6489,

%U 7819,8582,9694,11855,12967,14515,18083,19413,21574,26799,28708,32276

%N a(n) = a(n-1) + a(n - 1 minus the number of terms of a(k) == n (mod 3) so far).

%e a(5) = a(4) + a(4 - the number of terms congruent to 2 (mod 3) so far) = a(4) + a(4-2) = 5 + 2 = 7.

%t m[ 1 ] = 1; m[ 2 ] = 2; m[ 3 ] = 3; m[ n_Integer ] := m[ n ] = Block[ {a = b = c = 0}, Do[ Switch[ Mod[ m[ k ], 3 ], 0, a++, 1, b++, 2, c++ ], {k, 1, n - 1} ]; Switch[ Mod[ n, 3 ], 0, m[ n - 1 ] + m[ n - 1 - a ], 1, m[ n - 1 ] + m[ n - 1 - b ], 2, m[ n - 1 ] + m[ n - 1 - c ] ] ]; Table[ m[ n ], {n, 1, 50} ]

%K nonn

%O 1,2

%A _Robert G. Wilson v_, Apr 22 2001