AtCoder- A+...+B Problem

AtCoder- A+…+B Problem
这N个整数均属于区间[A,B],那么这N个数的和的最小可能是A+A+…+A+B=(N-1)A+B,最大可能是A+B+B+…+B=A+(N-1)B,所以可能的数量就是(n-1)*b+a -(n-1)*a-b +1

int main()
{
    
    

    cin>>n;

    cin>>a>>b;
    if(a > b || (n <= 1 && a != b) ) {
    
    
        cout<<0;
        return 0;
    }
    cout<<(n-1)*b+a -(n-1)*a-b +1;
    
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43567222/article/details/114703469
今日推荐