Sums of Blue and Red Cubes
InterviewTime limit2sMemory limit1024 MB
Count the pairs (x, y) with x and y each taken from the integers a to b whose sum lies between c and d inclusive.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Krosh received several gifts on a holiday. Barash and Losyash each gave him a set of cubes. Barash gave blue cubes and Losyash gave red cubes. Each set has one cube for every integer from to inclusive, and no two cubes in the same set share a number.
Krosh chooses two numbers and . He then picks one blue cube and one red cube so that the sum of their numbers is between and inclusive. Count the number of ways to do this.
Input
The input is a single line with four integers , , , and . , .
Output
Print one integer: the number of ways to choose one blue cube and one red cube so that their sum is in the given range.