Explanation:
There are 5 terms in the sequence. They are: 3, 5, 7, 9, and 11. For every length (from 1 to 5) of prefix we get the following sequence:
For L = 1, S = (3 % 1 = 0) = (0).
For L = 2, S = (3 % 2 = 1, 5 % 2 = 1) = (1, 1).
For L = 3, S = (3 % 3 = 0, 5 % 3 = 2, 7 % 3 = 1) = (0, 2, 1)
For L = 4, S = (3 % 4 = 3, 5 % 4 = 1, 7 % 4 = 3, 9 % 4 = 1) = (3, 1, 3, 1).
For L = 5, S = (3 % 5 = 3, 5 % 5 = 0, 7 % 5 = 2, 9 % 5 = 4, 11 % 5 = 1) = (3, 0, 2, 4, 1).
So for L = 1, 3 and 5 we get the desired output. So the answer is 3.

This is a companion discussion topic for the original entry at https://toph.co/p/beauty-of-ap