CF 215A - Bicycle Chain
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .
Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
In the problem, fraction denotes division in real numbers, that is, no rounding is performed.
Input
The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing.
The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing.
It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
Output
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
-------------------------------
Vasya 的自行车链条传动由两部分组成:n 颗星附着在踏板轴上,m 颗星附着在后轮轴上。 链条通过传递踏板旋转来帮助后轮旋转。
我们知道踏板轴上的第i颗星有ai(0 < a1 < a2 < ... < an)齿,后轮轴上的第j颗星有bj(0 < b1 < b2 < 。 ... < bm) 牙齿。 任何对 (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) 称为齿轮,并设置链当前所连接的恒星的索引。 Gear (i, j) 的齿轮比等于值 。
由于 Vasya 喜欢整数,他想找到这样的齿轮 (i, j),其比率为整数。 另一方面,Vasya 喜欢快速驾驶,因此在所有“整数”档位 (i, j) 中,他想选择速比最大的档位。 帮助他找到这样的齿轮的数量。
问题中,分数表示实数除法,即不进行舍入。
输入
第一个输入行包含整数 n (1 ≤ n ≤ 50) — 自行车踏板轴上的星星数量。 第二行包含n个整数a1, a2, ..., an (1 ≤ ai ≤ 104),按照严格递增的顺序。
第三输入行包含整数 m (1 ≤ m ≤ 50)——后轮轴上的星星数量。 第四行包含 m 个整数 b1, b2, ..., bm (1 ≤ bi ≤ 104),按严格递增的顺序排列。
保证至少存在一个档位(i, j),且其传动比为整数。 行上的数字由空格分隔。
输出
打印所有“整数”齿轮中传动比最大的“整数”齿轮的数量。
------------------------
一个是用来保存最大值的,一个是用来存储每个值存在的次数的,最后返回最大值的次数即可;
下面是代码:

