#P4132. [BJOI2012] 算不出的等式

[BJOI2012] 算不出的等式

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, pp and qq 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,qp, q.

Output Format

A single number, the value of the expression.

5 7
6

Hint

p,q<232p, q < 2^{32}.

Translated by ChatGPT 5