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

建议使用的浏览器:

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

2835:Sunzi's Problem

Special Judge 特殊评判
题目描述

In the ancient work Sunzi Suanjing (Master Sun’s Mathematical Manual), the problem below was mentioned.

We have a number of things, but we do not know exactly how many. If we count them by threes we have two left over. If we count them by fives we have three left over. If we count them by sevens we have two left over. How many things are there?

Sunzi wrote in his work, “The answer is twenty-three.

In 1592, Dawei Cheng put the solution to the problem as a poem in Suanfa Tongzong (Systematic Treatise on Arithmetic).

Three septuagenarians walking together, ’tis rare!
Five plum trees with twenty one branches in flower,
Seven disciples gathering right by the half-moon,
One hundred and five taken away, lo the result shall appear!

In modern notation, Sunzi’s problem is to find a number x such that

x ≡ 2 (mod 3),
x ≡ 3 (mod 5),
x ≡ 2 (mod 7).

And Cheng’s solution is

x ≡ 2 × 70 + 3 × 21 + 2 × 15 ≡ 233 (mod 105).

The solution also indicates that if one is given three integers r1, r2, r3 and is asked to find a number x such that

xr1 (mod 3),
xr2 (mod 5),
xr3 (mod 7),

then the answer is

xr1 × 70 + r2 × 21 + r3 × 15 (mod 105).

For example, for r1 = 1, r2 = 4, r3 = 4, the answer is

x ≡ 1 × 70 + 4 × 21 + 4 × 15 ≡ 214 (mod 105).

In generalization, given n positive integers a1, a2, …, an, the problem is to determine whether there exist n positive integers b1, b2, …, bn such that for any positive integer N, let pi (1 ≤ in) be the remainder of N taken modulo ai and M = p1 × b1 + p2 × b2 + … + pn × bn, then Mpi (mod ai) for all i (1 ≤ in); and to find a set of values of b1, b2, …, bn if they exist.

输入解释

The input consists of multiple test cases. Each test case is given in one line. In each test case, given first is the integer n (1 ≤ n ≤ 10), which is followed by a1, a2, …, an (ai ≤ 50, 1 ≤ in). The last case, with n = 0, indicates the end of input and should not be processed.

输出解释

For each test case, output one line. If the positive integers b1, b2, …, bn exist, output them (none of them should be longer than 50 decimal digits) separated by single spaces. If there are multiple answers, output any one. Output “NO” if they do not exist.

输入样例
3 3 5 7
0
输出样例
70 21 15
提示

Mind your program’s output format since special judge is used.


该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 PKU Local 2006, kicc

源链接: POJ-2835

最后修改于 2020-10-29T06:45:25+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536