编程介的小学生 2018-12-03 14:42 采纳率: 20.5%
浏览 422
已采纳

GCD,一个数字的生成的问题,有点困难,不会

Problem Description
Mr. Frog likes generating numbers! He can generate many numbers from a sequence.

For a given sequence a1,a2,⋯,an Mr. Frog can choose two numbers l and r (1≤l≤r≤n) and calculate the gcd between l-th and r-th number in this sequence g=gcd(al,al+1,⋯,ar). 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 ap to vi. After each modification, you are asked to tell how many distinct numbers can be generated by this sequence immediately!

Input
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≤n,q≤50000). which indicate the length of sequence and the number of modifications.

The second line contains n numbers:a1,a2,⋯,an.

Then q lines, each line contain two numbers, pi,vi(1≤pi≤n,1≤vi≤1000000).

Test data guarantee that 1<≤ai≤1000000 all the time and the sum of all n and q is less than or equal to 2×105.

Output
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.

Sample Input
2
3 2
1 2 3
1 3
2 3

3 2
3 3 3
1 1
2 2

Sample Output
Case #1:
3
1
Case #2:
2
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-03-28 10:41
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行