P4132 [BJOI2012] The Uncomputable Equation

Background

Once there was a cheesy old game right in front of me, and I didn’t cherish it. Only when the game was discontinued did I deeply regret it. There is nothing more painful in this world than that. If heaven gave me one more chance to play it, I would definitely beat it!

Description

If you really want to play this game, then take a look at my problem first. If you can’t handle these, you won’t be able to clear the game. The first level is actually simple: there is only a locked door with a password. There is a strange formula written on the door; I guess you are supposed to use it to compute the password to open the door (what a cliché). Legend says that in this expression, $p$ and $q$ are two odd primes. The computed value should be the password. Can you really not work it out? $$ \sum_{k=1}^{\frac{p-1}{2}} \biggl\lfloor\frac{kq}{p}\biggr\rfloor+\sum_{k=1}^{\frac{q-1}{2}} \biggl\lfloor\frac{kp}{q}\biggr\rfloor $$

Input Format

A single line containing two odd primes, denoting $p, q$.

Output Format

A single number, the value of the expression.

Explanation/Hint

$p, q < 2^{32}$. Translated by ChatGPT 5