Problem:


Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1



Sample input:
4 4 6


Sample output:
5

Submission status: Runtime Error

Solution code:
N, A, B = map(int, raw_input().split())

def fact(n, c):
    if c == 0:  return 1
    return n * fact(n - 1, c - 1)

if B < A:
    print(0)
elif N == 1:
    if 1 < (B - A):
        print(0)
    else:
        print(1)
else:
    result1 = fact(B - A + 2, N - 2) / fact(N - 2, N - 2)

    minimum = A * (N - 1) + B
    maximum = A + B * (N - 1)
    result2 = maximum - minimum + 1

    result = min(result1, result2)
    print(result)

Submission status: Runtime Error

Solution code:
#! -*- coding:utf-8 -*-
import itertools

n,a,b = map(int,input().split())

l = range(a,b+1)
arr = []
if a > b:
    print(0)
elif n == 1 and a == b:
    print(1)
elif n == 1 and a != b:
    print(0)
else:
    for elem in itertools.combinations_with_replacement(l,n-2):
        #sum = a + b
        arr.append(sum(elem))
    print(len(set(arr)))

Submission status: Runtime Error

Solution code:
import itertools
n = [int(i) for i in input().split()]
if n[0] == 1 and n[1] < n[2]:
    print(0)
elif n[1]>n[2]:
    print(0)
elif n[0] == 1 and n[1]==n[2]:
    print(1)
else:
    m = range(n[1],n[2]+1)
    l = n[0]-2
    c = list(itertools.combinations(m,l))
    c.extend([(i,i) for i in m])
    print(len(set([i+j for i,j in c])))

Submission status: Runtime Error

Solution code:
import itertools

def main():
    N, A, B = map(int, input().split())

    num = tuple(range(A, B+1))
    val = []
    for n in itertools.combinations_with_replacement(num, N):
        if n[0] == A and n[-1] == B:
            val.append(sum(n))

    ans = len(set(val))
    print(ans)

main()

Submission status: Runtime Error

Solution code:
#! -*- coding:utf-8 -*-
import itertools

n,a,b = map(int,input().split())

l = range(a,b+1)
arr = []
if a > b:
    print(0)
elif n == 1 and a == b:
    print(1)
elif n == 1 and a != b:
    print(0)
else:
    for elem in itertools.combinations_with_replacement(l,n-2):
        sum = a + b
        for i in range(len(elem)):
            sum += elem[i]
        arr.append(sum)
    try:
        print(len(set(arr)))
    except:
        print(0)

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def FI(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline().split())
def S(): return input()

n, a, b = LI()

if a>b:
	print(0)
elif n=1 and a!=b:
	print(0)
else:
	mi = a*(n-1)+b
	ma = a+b*(n-1)
	print(ma-mi+1)

Submission status: Runtime Error

Solution code:
#! -*- coding:utf-8 -*-
import itertools

n,a,b = map(int,input().split())

l = range(a,b+1)
arr = []
if a > b:
    print(0)
elif n == 1 and a == b:
    print(1)
elif n == 1 and a != b:
    print(0)
else:
    for elem in itertools.combinations_with_replacement(l,n-2):
        sum = a + b
        for i in range(len(elem)):
            sum += elem[i]
        arr.append(sum)
    print(len(set(arr)))