Count of distinct sums formed by N numbers taken form range [ L , R ] | C ++ program for the above approach ; Function to find total number of different sums of N numbers in the range [ L , R ] ; To store minimum possible sum with N numbers with all as L ; To store maximum possible sum with N numbers with all as R ; All other numbers in between maxSum and minSum can also be formed so numbers in this range is the final answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDistinctSums ( int N , int L , int R ) { int minSum = L * N ; int maxSum = R * N ; return maxSum - minSum + 1 ; } int main ( ) { int N = 2 , L = 1 , R = 3 ; cout << countDistinctSums ( N , L , R ) ; return 0 ; }