#P2520. 墨墨的等式

墨墨的等式

墨墨的等式

  • 时间限制:1 秒
  • 内存限制:1024 MiB

题目描述

墨墨正在研究等式

∑i=1naixi=b\sum_{i=1}^{n} a_i x_i=b

存在非负整数解的条件。

给定 n,a1,a2,…,an,l,rn,a_1,a_2,\ldots,a_n,l,r,请你求出有多少个整数 b∈[l,r]b\in[l,r],使得上述等式存在一组非负整数解 x1,x2,…,xnx_1,x_2,\ldots,x_n。

输入格式

第一行包含三个整数 n,l,rn,l,r。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n。

输出格式

输出一行一个整数,表示满足条件的 bb 的数量。

样例输入 1

2 5 10
3 5

样例输出 1

5

数据范围

对于 20%20\% 的数据,n≤5n\le 5,r≤10r\le 10。

对于 40%40\% 的数据,n≤10n\le 10,r≤106r\le 10^6。

对于 100%100\% 的数据,1≤n≤121\le n\le 12,0≤ai≤5×1050\le a_i\le 5\times10^5,1≤l≤r≤10121\le l\le r\le 10^{12}。