TITLE: Spivak' Calculus Chapter 7 Problem 19(b) [continuity]
QUESTION [5 upvotes]: The question is from Spivak's Calculus 3rd Ed: 

Suppose $ 0<a<1 $, but that $a$ is not equal to $1/n$ for any natural number $n$.  Find a function $f$ which is continuous on $[0,1]$ and which satisfies $ f(0) = f(1) $, but which does not satisfy $f(x) = f(x+a)$ for any $x$.

The solution from Spivak's solutions book is as follows:

In general if $ {1 \over n+1} <a< {1 \over n} $ then define $f$ arbitrarily on $[0,a]$, subject only to $f(0)=0 , f(a)>0$ and  $f(1-na)=-nf(a).$  Then define $f$ on $[ka,(k+1)a]$ by $ f(ka+x)=f(x)+ ka.$  In particular we have, we have $f(1) = f(na + (1-na))= na+f(1-na)=0$ but $f(x+a)-f(a)=f(a)>0$ for all $x$.

I don't see how we get $na+f(1-na)=0$ and the final $f(x+a)-f(a)=f(a)>0$ for all $x$.
EDIT:  Post below found an error in the answer book.  Instead we require $f(ka+x)=k\color{red}{f(a)}+f(x)$, then we have $f(1)=0$ and the final statement also follows.

REPLY [7 votes]: You are justified in being a bit confused, as there is a typo in Spivak's solution.
First of all, note that $0<1-na<1-\frac n{n+1}=\frac 1{n+1}$, so $1-na\in (0,a)$. Next, there is a typo in what you typed: It should be that $f(1)=f(na+(1-\color{red}{n}a))$. But there is also a typo in Spivak's solution: He should have set $f(ka+x)=k\color{red}{f(a)}+f(x)$. [A consequence of this is that $f(ka) = kf(a)$ for all $k=1,\dots,n$.] So then $f(1) = nf(a) + f(1-na) = nf(a) + (-nf(a)) = 0$.
Last, note that when $t\in [ka,(k+1)a]$ for some $k=0,1,\dots,n-1$, we have $t=ka+x$ for some $x\in [0,a]$, so $f(t)=kf(a)+f(x)$. On the other hand, $t+a = (k+1)a+x$, so $f(t+a)= (k+1)f(a)+f(x)$, from which we conclude that $f(t+a)-f(t)=f(a)>0$ for all $t\in [0,1-a]$.