
countSumOfTwoRepresentations
Given integers n
, l
and r
, find the number of ways to represent n
as a sum of two integers A
and B
such that l ≤ A ≤ B ≤ r
.
Example
- For
n = 6
,l = 2
, andr = 4
, the output should becountSumOfTwoRepresentations2(n, l, r) = 2.
There are just two ways to write6
asA + B
, where2 ≤ A ≤ B ≤ 4
:6 = 2 + 4
and6 = 3 + 3
.
Input/Output
-
[execution time limit] 3 seconds
-
[input] integer n
A positive integer.
Guaranteed constraints:
5 ≤ n ≤ 109
. -
[input] integer l
A positive integer.
Guaranteed constraints:
1 ≤ l ≤ r
. -
[input] integer r
A positive integer.
Guaranteed constraints:
l ≤ r ≤ 109
,r - l ≤ 106
.
Post Comment