#P1447. Energy Loss Calculation

    ID: 14733 Type: Default 1000ms 256MiB

Energy Loss Calculation

Energy Loss Calculation

Dongdong has a rectangular field where he plants a special energy plant that collects solar energy. The plants are arranged in a grid with \(n\) columns and \(m\) plants in each column. Each plant is identified by its coordinate \((x, y)\), with \(1 \le x \le n\) and \(1 \le y \le m\). The energy aggregator, which is immovable due to its large size, is placed at coordinate \((0, 0)\).

When connecting a plant at \((x, y)\) to the aggregator, if there are \(k\) plants (lying strictly on the line segment between \((0, 0)\) and \((x, y)\)) then the energy loss incurred is \(2k+1\). Note that if there are no plants on the connecting line, then the loss is \(1\).
For example, for the plant at \((2, 4)\), the line from \((0, 0)\) to \((2, 4)\) passes through \((1,2)\) (since \((2,4) = 2\times(1,2)\)). Thus, \(k=1\) and the loss is \(2\times1+1=3\).

Your task is to compute the total energy loss for all the plants. Mathematically, for each plant at \((x, y)\), the energy loss is given by:

\[ L(x,y)=2\cdot\gcd(x,y)-1, \]

and the total loss is the sum over all plants:

\[ Total = \sum_{x=1}^{n} \sum_{y=1}^{m} (2\cdot\gcd(x,y)-1). \]</p>

inputFormat

The input consists of a single line containing two positive integers \(n\) and \(m\) (\(1 \le n, m \le 10^5\)), representing the number of columns and the number of plants in each column, respectively.

outputFormat

Output a single integer which is the total energy loss incurred when collecting energy from all the plants.

sample

5 4
36