Calculating a sum with Euler's totient function If $S(a,b)= \{ k \in \mathbb{Z} \mid a ~ (\mathrm{mod} ~ k) + b ~ (\mathrm{mod} ~ k) \ge k \}$, calculate the following sum
$$\sum_{k\in S(m,n)}\varphi(k)$$
where $\varphi$ is Euler's totient function.

I have noticed that all $k$'s such that $$\max(a,b) < k \le a + b$$ are in $S(a,b)$.
(One more not important note) it seems that $$k \in S(n,n) \iff n ~ (\mathrm{mod} ~ k) \ge \left\lfloor  \frac{n}{2} \right\rfloor$$
However, I still haven't discovered any way to actually solve the problem. Your help is appreciated.
 A: Now that's a nice little problem. We don't need much to solve it, just the known fact that $\sum\limits_{k|n}\varphi(k)=n$, and a little insight.
Apparently, $S(a,b)$ is complicated and won't be described easily. But we don't really need that. Let's see how is $S(a,b)$ different from $S(a,b-1)$.
What happens when we add $1$ to the (second) argument? Well, $b\pmod k$ either increases by $1$ or drops to $0$, depending on $k$. Consequently, some numbers vanish from the set, and some other numbers join it, and the rest stay where they were.

*

*What are the numbers that vanish from the set? It is exactly those for which $b\pmod k=0$, that is, the divisors of the new $b$†.

*What are the numbers that join the set? It is those for which $a\pmod k + b\pmod k$ was exactly $1$ short of $k$ prior to the increase. In other words, after the increase we have $a\pmod k + b\pmod k = k$, which means $(a+b)\pmod k =0$, which means the divisors of $a+b$†.


† Technically, those $k$ which are also divisors of $a$ (if any) must be excluded from both sets, but that's not important. We may just as well consider them included, for they will cancel out in the end.
Let's call the sum in question $Sum(a,b)$. Together with the fact mentioned earlier, we have $Sum(a,b)-Sum(a,b-1) = \sum\limits_{k|a+b}\varphi(k) - \sum\limits_{k|b}\varphi(k) = a+b-b = a$. Together with the obvious $S(a,0)=\emptyset\iff Sum(a,0)=0$ we have the final result:
$$Sum(a,b) = a\cdot b$$
So it goes.
