What about a combination

(n=0...[T/2])?

Basically the result of a fourier transformation, using the symmetry to get rid of the sin expressions.

In the T=3 case:

2/3-2/3cos(2pi x/3) goes 0110110...

In the T=4 case:

cos(0) goes 1, 1, 1, 1, 1,...

cos(2pi x/4) goes 1, 0, -1, 0, 1, ...

cos(4pi x/4) goes 1, -1, 1, -1, 1, ...

This gives you three interesting equations, using a

_{0} to a

_{2} as coefficients:

a

_{0}+a

_{1}+a

_{2}=0 (for f(0)=0)

a

_{0}-a

_{2}=1 (for f(1)=1)

a

_{0}-a

_{1}+a

_{2}=1 (for f(2)=1)

This is solved by a=3/4, b=-1/2, c=-1/4

Task for you: Check that 3/4 cos(0) - 1/2 cos(pi x/2) - 1/4 cos(pi x) is a solution.

And perform a fourier transformation for the general formula.