A warehouse conveyor carries crates numbered 1 through n in order. Every crate whose number is exactly divisible by the facility's inspection interval m is diverted onto the quality-control line; every other crate rolls straight onto the shipping line. At the end of the shift the floor manager wants to compare the two lines: the total of all crate numbers that went to shipping, minus the total of all crate numbers that went to quality control.
A single line containing two integers n and m.
Print a single integer: (sum of shipping-line crate numbers) minus (sum of quality-control-line crate numbers). This value may be negative.
Example 1
Input
10 3
Expected
19
Explanation
Crates 3, 6, and 9 are divisible by 3 and go to quality control, summing to 18. The remaining crates 1, 2, 4, 5, 7, 8, 10 go to shipping, summing to 37. 37 - 18 = 19.
Example 2
Input
5 2
Expected
3
Explanation
Crates 2 and 4 are divisible by 2 and go to quality control, summing to 6. Crates 1, 3, 5 go to shipping, summing to 9. 9 - 6 = 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →