102594: [AtCoder]ABC259 E - LCM on Whiteboard

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

There are $N$ integers $a_1,\ldots,a_N$ written on a whiteboard.
Here, $a_i$ can be represented as $a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}}$ using $m_i$ prime numbers $p_{i,1} \lt \ldots \lt p_{i,m_i}$ and positive integers $e_{i,1},\ldots,e_{i,m_i}$.
You will choose one of the $N$ integers to replace it with $1$.
Find the number of values that can be the least common multiple of the $N$ integers after the replacement.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq m_i$
  • $\sum{m_i} \leq 2 \times 10^5$
  • $2 \leq p_{i,1} \lt \ldots \lt p_{i,m_i} \leq 10^9$
  • $p_{i,j}$ is prime.
  • $1 \leq e_{i,j} \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$m_1$
$p_{1,1}$ $e_{1,1}$
$\vdots$
$p_{1,m_1}$ $e_{1,m_1}$
$m_2$
$p_{2,1}$ $e_{2,1}$
$\vdots$
$p_{2,m_2}$ $e_{2,m_2}$
$\vdots$
$m_N$
$p_{N,1}$ $e_{N,1}$
$\vdots$
$p_{N,m_N}$ $e_{N,m_N}$

Output

Print the answer.


Sample Input 1

4
1
7 2
2
2 2
5 1
1
5 1
2
2 1
7 1

Sample Output 1

3

The integers on the whiteboard are $a_1 =7^2=49, a_2=2^2 \times 5^1 = 20, a_3 = 5^1 = 5, a_4=2^1 \times 7^1 = 14$.
If you replace $a_1$ with $1$, the integers on the whiteboard become $1,20,5,14$, whose least common multiple is $140$.
If you replace $a_2$ with $1$, the integers on the whiteboard become $49,1,5,14$, whose least common multiple is $490$.
If you replace $a_3$ with $1$, the integers on the whiteboard become $49,20,1,14$, whose least common multiple is $980$.
If you replace $a_4$ with $1$, the integers on the whiteboard become $49,20,5,1$, whose least common multiple is $980$.
Therefore, the least common multiple of the $N$ integers after the replacement can be $140$, $490$, or $980$, so the answer is $3$.


Sample Input 2

1
1
998244353 1000000000

Sample Output 2

1

There may be enormous integers on the whiteboard.

Input

题意翻译

给定 $n$ 个用唯一分解表示的数,你需要将其中一个置为 $1$ 使得这 $n$ 个数的最小公倍数最小。 唯一分解:即每个正整数 $x$ 都可以表示为 $$\prod p_i^{k_i}$$ 的形式,其中 $p_i$ 表示质数。

Output

得分:500分

问题描述

白板上写有$N$个整数$a_1,\ldots,a_N$。

其中,$a_i$可以用$m_i$个质数$p_{i,1} \lt \ldots \lt p_{i,m_i}$和正整数$e_{i,1},\ldots,e_{i,m_i}$表示为$a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}}$。

你需要从这$N$个整数中选择一个并将其替换为$1$。

找出替换后$N$个整数的最小公倍数的可能值的数量。

约束

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq m_i$
  • $\sum{m_i} \leq 2 \times 10^5$
  • $2 \leq p_{i,1} \lt \ldots \lt p_{i,m_i} \leq 10^9$
  • $p_{i,j}$是质数。
  • $1 \leq e_{i,j} \leq 10^9$
  • 输入中的所有值都是整数。

输入

从标准输入按以下格式给出输入:

$N$
$m_1$
$p_{1,1}$ $e_{1,1}$
$\vdots$
$p_{1,m_1}$ $e_{1,m_1}$
$m_2$
$p_{2,1}$ $e_{2,1}$
$\vdots$
$p_{2,m_2}$ $e_{2,m_2}$
$\vdots$
$m_N$
$p_{N,1}$ $e_{N,1}$
$\vdots$
$p_{N,m_N}$ $e_{N,m_N}$

输出

打印答案。


样例输入1

4
1
7 2
2
2 2
5 1
1
5 1
2
2 1
7 1

样例输出1

3

白板上的整数是$a_1 =7^2=49, a_2=2^2 \times 5^1 = 20, a_3 = 5^1 = 5, a_4=2^1 \times 7^1 = 14$。

如果你将$a_1$替换为$1$,白板上的整数变为$1,20,5,14$,它们的最小公倍数为$140$。

如果你将$a_2$替换为$1$,白板上的整数变为$49,1,5,14$,它们的最小公倍数为$490$。

如果你将$a_3$替换为$1$,白板上的整数变为$49,20,1,14$,它们的最小公倍数为$980$。

如果你将$a_4$替换为$1$,白板上的整数变为$49,20,5,1$,它们的最小公倍数为$980$。

因此,替换后$N$个整数的最小公倍数可以是$140$、$490$或$980$,所以答案是$3$。


样例输入2

1
1
998244353 1000000000

样例输出2

1

白板上可能存在巨大的整数。

加入题单

上一题 下一题 算法标签: