Count of distinct sums formed by N numbers taken form range [ L , R ] | 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
function countDistinctSums ( N , L , R ) { let minSum = L * N ; let maxSum = R * N ; return maxSum - minSum + 1 ; } let N = 2 , L = 1 , R = 3 ; document . write ( countDistinctSums ( N , L , R ) ) ;