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

建议使用的浏览器:

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

5930:GCD

题目描述
Mr. Frog likes generating numbers! He can generate many numbers from a sequence.

For a given sequence $a_1,a_2,\cdots ,a_n$ Mr. Frog can choose two numbers l and r ($1 \leq l \leq r \leq n$) and calculate the gcd between l-th and r-th number in this sequence $g = gcd(a_l,a_{l+1},\cdots ,a_r)$. Asan expert in generating numbers, Mr. Frog wants to know how many distinct numbers can be generated by a sequence.

Mr. Frog likes challenges, so there may be many modifications in this sequence. In the i-th modification, Mr. Frog may change $a_p$ to $v_i$. After each modification, you are asked to tell how many distinct numbers can be generated by this sequence immediately!
输入解释
The first line contains only one integer T, which indicates the number of test cases.

For each test case, the first line includes two numbers n, q($1 \leq n,q \leq 50000$). which indicate the length of sequence and the number of modifications.

The second line contains n numbers:$a_1,a_2,\cdots ,a_n$.

Then q lines, each line contain two numbers, $p_i,v_i(1 \leq p_i \leq n, 1 \leq v_i \leq 1000000)$.

Test data guarantee that $1 <\leq a_i \leq 1000000$ all the time and the sum of all n and q is less than or equal to $2 \times 10^5$.
输出解释
For each test case, first output one line "Case #x:", where x is the case number (starting from 1). Then q lines, each line contain only one number, which is the answer to current sequence.
输入样例
2
3 2
1 2 3
1 3
2 3

3 2
3 3 3
1 1
2 2
输出样例
Case #1:
3
1
Case #2:
2
3
提示
For case 1, after the first operation, 3,2,1 can be generated by the sequence 3, 2, 3. Whereas after the second operation, sequence 3, 3, 3 can generate only 3. 
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5930

最后修改于 2020-10-25T23:26:50+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
9000/4500MS(Java/Others) 65536/65536K(Java/Others)