当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1681:Frobenius

题目描述
The Frobenius problem is an old problem in mathematics, named after the German mathematician G. Frobenius (1849–1917).

Let a1, a2, …, an be integers larger than 1, with greatest common divisor (gcd) 1. Then it is known that there are finitely many integers larger than or equal to 0, that cannot be expressed as a linear combination w1a1 + w2a2 + … + wnan using integer coefficients wi ≥ 0. The largest of such nonnegative integers is known as the Frobenius number of a1, a2, …, an (denoted by F(a1, a2, …, an)). So: F(a1, a2, …, an) is the largest nonnegative integer that cannot be expressed as a nonnegative integer linear combination of a1, a2, …, an.

For n = 2 there is a simple formula for F(a1, a2). However, for n ≥ 3 it is much more complicated. For n = 3 only for some special choices of a1, a2, a3 formulas exist. For n > 4 no formulas are known at all.

We will consider here the Frobenius problem for n = 4. In this case our version of the problem can be formulated as follows. Let four integers a, b, c and d be given, with a, b, c, d > 1 and gcd(a, b, c, d) = 1. We want to know two things.

How many nonnegative integers less than or equal to 1,000,000 cannot be expressed as a nonnegative integer linear combination of the values a, b, c and d?
Is the Frobenius number of a, b, c and d less than or equal to 1,000,000 and if so, what is its value?
输入解释
The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

One line, containing four integers a, b, c, d (with 1 < a, b, c, d ≤ 10, 000 and gcd(a, b, c, d) = 1), separated by single spaces.
输出解释
For every test case in the input file, the output should contain two lines.

The first line contains the number of integers between 0 and 1,000,000 (boundaries included) that cannot be expressed as a*w + b*x + c*y + d*z, where w, x, y, z are nonnegative (meaning ≥ 0) integers.
The second line contains the Frobenius number if this is less than or equal to 1,000,000 and otherwise &#8722;1, meaning that the Frobenius number of a, b, c and d is larger than 1,000,000.
输入样例
3
8 5 9 7
5 8 5 5
1938 1939 1940 1937
输出样例
6
11
14
27
600366
-1
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-1681

最后修改于 2020-10-25T22:47:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000/1000MS(Java/Others) 32768/32768K(Java/Others)