问题1696--【USACO】Scavenger Hunt(残酷的猎杀)

1696: 【USACO】Scavenger Hunt(残酷的猎杀)

时间限制: 1.000 Sec  内存限制: 64 MB
提交: 55  解决: 43
[提交] [状态] [讨论版] [命题人:]

题目描述

Farmer John has scattered treats for Bessie at special places in the pasture. Since everyone knows that smart cows make tasty milk, FJ has placed the treats at locations that require Bessie to think. He has given her two numbers, P and Q (1 <= P <= 6,000; 1 <= Q <= 6,000), and she has to check every point in the pasture whose x-coordinate is a factor of P and whose y-coordinate is a factor of Q to find her treat. Suppose FJ gives Bessie P = 24 and Q = 2. Here are all of their respective factors: P = 24 => 1, 2, 3, 4, 6, 8, 12, 24 Q = 2 => 1, 2 Bessie would thus check grid locations: (1, 1), (1, 2), (2, 1), (2, 2), (3, 1)... Help Bessie by printing all of the points she ought to check.

农场主约翰在牧场上的一些特别的地方给贝西分发了一些食物。既然每个人都知道聪明的奶牛会产出美味的牛奶,FJ已经把这些食物放在了需要贝西思考的地方。他给了她两个数字,p和q(1<=p<=6000;1<=q<=6000),她必须检查牧场上的每一个点,其x坐标是p的一个因子,而y坐标是q的一个因子,才能找到她的治疗方法。假设Fj给贝西p=24,q=2。下面是它们各自的因素:p=24=>1,2,3,4,6,8,12,24 q=2=>1,2,Bessie将检查网格位置:(1,1),(1,2),(2,1),(2,2),(3,1)……帮助贝西打印她应该检查的所有要点。

输入

* Line 1: Two space separated integers: P and Q

*第1行:两个空格分隔的整数:p和q

输出

* Lines 1..?: A complete list of unique pairs of space-separated integers sorted by the first number and, if tied, the second number: a factor of P followed by a factor of Q

*行1…?:由第一个数字和第二个数字(如果是绑定的话)排序的、以空格分隔的整数的唯一对的完整列表:p的一个因子,后跟q的一个因子。

样例输入 复制

24 2

样例输出 复制

1 1 1 2 2 1 2 2 3 1 3 2 4 1 4 2 6 1 6 2 8 1 8 2 12 1 12 2 24 1 24 2

来源/分类


[提交] [状态]