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

Solution in Lua (5.3.2) (judge verdict: Accepted)


local format = string.format
local find = string.find
local reverse = string.reverse
local sub = string.sub
local upper = string.upper
local lower = string.lower
local rep = string.rep
local char = string.char
local byte = string.byte
local gsub = string.gsub
-- gsub(s,"\\","/")
-- formula = "20% * 2"
-- formula = string.gsub(formula,"%%","/100")
-- str = " x x 11 "
-- str = string.gsub(str, "[%s%p]", "")
local gmatch = string.gmatch
-- for token in string.gmatch(arr_temp, "[^%s]+") do
local match = string.match

local concat = table.concat
local insert = table.insert
local remove = table.remove
local sort = table.sort

local abs = math.abs
local min = math.min
local max = math.max
local floor = math.floor
local ceil = math.ceil
local sin = math.sin
local cos = math.cos
local tan = math.tan
local deg = math.deg
local log = math.log
local mod = math.mod
local random = math.random
local sqrt = math.sqrt



local lua_print = print
local tconcat = table.concat
local tinsert = table.insert
local srep = string.rep
local format = string.format
function print_long_str(str)
	local len = #str
	local cur = 1
	--每次最大输出15*1024, 超过就会蹦了
	while cur <= len do
		lua_print('\n'..string.sub(str,cur,cur + 15*1000))
		cur = cur + 15*1000 + 1
	end
	lua_print('')
end

function print_r(root)
	local cache = {[root] = "."}
	local function _dump(t,space,name)
		local temp = {}
		for k,v in pairs(t) do
			local key = tostring(k)
			if cache[v] then
				tinsert(temp,"+" .. key .. " {" .. cache[v].."}")
			elseif type(v) == "table" then
				local new_key = name .. "." .. key
				cache[v] = new_key
				tinsert(temp,"+" .. key .. _dump(v,space .. (next(t,k) and "|" or " " ).. srep(" ",#key),new_key))
			elseif type(v) == "function" then
				tinsert(temp,"+" .. key .. " [".. tostring(v).."]")
			else
				tinsert(temp,"+" .. key .. " [".. type(v) .. " " .. tostring(v).."]")
			end
		end
		return tconcat(temp,"\n"..space)
	end
	local str = _dump(root, "","")
	print_long_str(str)
end



-- @desc 数据长度
local function length(s)
	local l = 0
	for _ in pairs(s) do
		l = l + 1
	end
	return l
end

-- @desc 数据最小值
local function minn(s)
	local result
	for _, v in pairs(s) do
		if not result then
			result = v
		elseif v < result then
			result = v
		end
	end
	return result
end

-- @desc 数据最大值
local function maxn(s)
	local result
	for _, v in pairs(s) do
		if not result then
			result = v
		elseif v > result then
			result = v
		end
	end
	return result
end

-- @desc 数据和
local function sumn(s)
	local result = 0
	for _, v in pairs(s) do
		result = result + v
	end
	return result
end

-- local str = "fsdfas$123$fgds"
-- @desc split(str,'%$') --注意$是特殊字符 前面要加%！！ 结果返回{"fsdfas","123","fgds"}
local function split(str, sep)
	local ret = {}
	local pos = 0
	while true do
		local pp = string.find(str,sep,pos+1)
		if pp == nil then
			table.insert(ret,string.sub(str,pos+1))
			break
		else
			table.insert(ret,string.sub(str,pos+1,pp-1))
			pos = pp
		end
	end
	return ret
end

local specialSplitStr = "().%+-*?[]^$"
local specialSplitT = {}
for i = 1, #specialSplitStr do
	local c = string.sub(specialSplitStr, i, i)
	specialSplitT[c] = '%' .. c
end
-- @desc 按非特殊字符进行分割，如模式分割直接用split
function newSplit(str, symbol)
	symbol = specialSplitT[symbol] or symbol
	return split(str, symbol)
end

-- @desc 根据角度，返回速度方向矢量
local function getDir(angle)
	local rate = angle / 180 * math.pi
	return {math.cos(rate), math.sin(rate)}
end

function string.utf8charlen(char)
	if not char then
		return 0
	elseif char >= 240 then
		return 4
	elseif char >= 224 then
		return 3
	elseif char >= 192 then
		return 2
	else
		return 1
	end
end

-- 二分法获得table里小于等于value的最大下标
function bisectLeft(t, value)
    local left = 1
    local right = #t
    if t[right] <= value then
        return right
    end
    while left < right do
        local mid = math.floor((left + right) / 2)
        if t[mid] > value then
            right = mid
        else
            left = mid + 1
        end
    end
    return math.max(1, left - 1)
end
-- 二分法获得table里大于等于value的最小下标
function bisectRight(t, value)
    local left = 1
    local right = #t
    while left < right do
        local mid = math.floor((left + right) / 2)
        if t[mid] >= value then
            right = mid
        else
            left = mid + 1
        end
    end
    return right
end


-- ***** VJudge acm
-- ** input
-- a = io.read("*number")
-- local s = io.stdin:read("*l")
-- local k = io.stdin:read("*n", "*l")
-- io.read()
-- io.read("*n")

-- n = io.read("*number", "*l")
-- arr = {}
-- arr_temp = io.read()
-- arr_i = 1;
-- for token in string.gmatch(arr_temp, "[^%s]+") do
--    arr[arr_i] = token
--    arr_i = arr_i + 1
-- end
-- *****

n=io.read("*number")
a=io.read("*number")
b=io.read("*number")
function solve()
	if a > b then
		return 0
	end
	if n == 1 then
		if a == b then
			return 1
		else
			return 0
		end
	end
	return a + (n - 1) * b - ( b + (n - 1) * a ) + 1
end
print(solve())