#P7499. Counting Pairs with Target Sum
Counting Pairs with Target Sum
Counting Pairs with Target Sum
Given two integer intervals \([a,b]\) and \([c,d]\), an integer is chosen uniformly at random from each interval. Determine the probability that the sum equals \(e\). However, instead of outputting the probability, output the value obtained by multiplying this probability with \((b-a+1)(d-c+1)\). This result is guaranteed to be an integer, and in fact it represents the number of pairs \((x,y)\) such that \(x \in [a,b]\), \(y \in [c,d]\), and \(x+y=e\).
Note: All inputs are integers and it is given that \(a \le b\) and \(c \le d\).
inputFormat
The input consists of a single line containing five space-separated integers: \(a\), \(b\), \(c\), \(d\), and \(e\).
outputFormat
Output a single integer, which is the number of pairs \((x,y)\) such that \(x \in [a,b]\), \(y \in [c,d]\), and \(x+y = e\).
sample
1 3 1 3 4
3