P1447 [NOI2010] Energy Collection

Description

Dongdong has a rectangular field where he planted an energy plant that can harvest energy from sunlight. After these plants harvest energy, Dongdong uses an energy aggregation machine to gather all the energy collected by the plants. Dongdong planted the plants in a very neat grid: there are $n$ columns, and each column has $m$ plants, with equal spacing both horizontally and vertically. Therefore, for each plant, Dongdong can denote it by a coordinate $(x, y)$, where $x$ ranges from $1$ to $n$ and $y$ ranges from $1$ to $m$, meaning it is the $y$-th plant in column $x$. Because the energy aggregation machine is large and not easy to move, Dongdong placed it at a corner, exactly at the coordinate $(0, 0)$. There is some energy loss during the aggregation process. If the line segment connecting a plant and the energy aggregation machine contains $k$ plants, then the energy loss is $2k + 1$. For example, when the machine collects energy from the plant at $(2, 4)$, since there is a plant at $(1, 2)$ on the connecting segment, the loss is $3$. Note that if there are no plants on the line segment connecting the plant and the machine, then the energy loss is $1$. Now compute the total energy loss. Below is an example of energy collection with $n = 5$ and $m = 4$, for a total of $20$ plants. Each plant is labeled with the energy loss incurred when the machine collects its energy. ![](https://cdn.luogu.com.cn/upload/image_hosting/fhzpmm7b.png) In this example, the total energy loss is $36$.

Input Format

One line with two integers $n, m$.

Output Format

Output a single integer representing the total energy loss.

Explanation/Hint

- For 10% of the testdata: $n, m \le 10$. - For 50% of the testdata: $n, m \le 100$. - For 80% of the testdata: $n, m \le 10^3$. - For 90% of the testdata: $n, m \le 10^4$. - For 100% of the testdata: $1 \le n, m \le 10^5$. Translated by ChatGPT 5