#P1447. [NOI2010] 能量采集
[NOI2010] 能量采集
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 columns, and each column has plants, with equal spacing both horizontally and vertically. Therefore, for each plant, Dongdong can denote it by a coordinate , where ranges from to and ranges from to , meaning it is the -th plant in column .
Because the energy aggregation machine is large and not easy to move, Dongdong placed it at a corner, exactly at the coordinate .
There is some energy loss during the aggregation process. If the line segment connecting a plant and the energy aggregation machine contains plants, then the energy loss is . For example, when the machine collects energy from the plant at , since there is a plant at on the connecting segment, the loss is . Note that if there are no plants on the line segment connecting the plant and the machine, then the energy loss is . Now compute the total energy loss.
Below is an example of energy collection with and , for a total of plants. Each plant is labeled with the energy loss incurred when the machine collects its energy.

In this example, the total energy loss is .
Input Format
One line with two integers .
Output Format
Output a single integer representing the total energy loss.
5 4
36
3 4
20
Hint
- For 10% of the testdata: .
- For 50% of the testdata: .
- For 80% of the testdata: .
- For 90% of the testdata: .
- For 100% of the testdata: .
Translated by ChatGPT 5
京公网安备 11011102002149号