The sum of two continuous periodic functions is periodic if and only if the ratio of their periods is rational?

Let $f,g$ be continuous and periodic with period $p,q$ where $\alpha=\frac pq$ is irrational. Assume $f+g$ is periodic with period $r$. Let $f(x_0)=\max f$ and $g(x_1)=\max g$. Then the set $\{\,np+mq\mid n,m\in\mathbb Z\,\}$ is dense in $\mathbb R$. Let $\epsilon>0$. Then for some $\delta>0$, $|x-x_1|<\delta$ implies $g(x)>g(x_1)-\epsilon$. Let $np+mq$ differ by less than $\delta$ from $x_1-x_0$. Then $f(x_0+np)=\max f$ and $g(x_0+np)>\max g-\epsilon$. We conclude that $\max(f+g)=\max f+\max g$. So assume $(f+g)(x_2)=\max (f+g)=\max f+\max g$. Then $(f+g)(x_2+nr)=\max(f+g)$ implies that also $f(x_2+nr)=\max f$ and $g(x_2+nr)=\max g$. At least one of $\frac rp$, $\frac rq$ is irrational, say $\frac rp$ is irrational. Then the set $\{\,x_2+nr+mp\mid n,m\in\mathbb Z\,\}$ is dense in $\mathbb R$ and we conclude that $f(x)=\max f$ on this dense set and hence throughout. Thus $f$ is constant.

In summary: The sum of two nonconstant continuous periodic functions with incommensurable periods is not periodic.