12 May 2017

Count Sum Of Two Representations 2

My solution:
int countSumOfTwoRepresentations2(int n, int l, int r) 
{
    var count = 0;
    for (var a = l; a <= r; a++)
        if (a <= n - a && n - a >= l && n - a <= r)
            count++;

    return count;
}

Previous Next