题库练习 Cutting Rectangle
← 上一题 下一题 →

A11707 | Cutting Rectangle

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectangles were of $n$ different types. Two rectangles are different if at least one side of one rectangle isn't equal to the corresponding side of the other. Note that the rectangle can't be rotated, this means that rectangles $a \times b$ and $b \times a$ are considered different if $a \neq b$ .

For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle.

Calculate the amount of pairs $(A; B)$ such as the given rectangles could be created by cutting the rectangle with sides of lengths $A$ and $B$ . Note that pairs $(A; B)$ and $(B; A)$ are considered different when $A \neq B$ .

输入格式

The first line consists of a single integer $n$ ( $1 \leq n \leq 2 \cdot 10^{5}$ ) — amount of different types of rectangles left after cutting the initial rectangle.

The next $n$ lines each consist of three integers $w_{i}, h_{i}, c_{i}$ $(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$ — the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type.

It is guaranteed that the rectangles of the different types are different.

输出格式

Output one integer — the answer to the problem.

输入输出样例

输入 #1
1
1 1 9
输出 #1
3
输入 #2
2
2 3 20
2 4 40
输出 #2
6
输入 #3
2
1 2 5
2 3 5
输出 #3
0
C++ 编辑器
输入
输出