博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 475 D. CGCDSSQ
阅读量:6888 次
发布时间:2019-06-27

本文共 1406 字,大约阅读时间需要 4 分钟。

暴力+维护某个数到前面一个能产生不同GCD的数的位置.......

D. CGCDSSQ
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi.

 is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest positive integer that divides all vi.

Input

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers a1, ..., an, (1 ≤ ai ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer xi, (1 ≤ xi ≤ 109).

Output

For each query print the result in a separate line.

Sample test(s)
input
32 6 3512346
output
12201
input
710 20 3 15 1000 60 16101234561020601000
output
14022202211

#include 
#include
#include
#include
#include
using namespace std;typedef long long int LL;const int maxn=100100;map
ans;int a[maxn],n,m;int pre[maxn];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",a+i); for(int i=1;i<=n;i++) { pre[i]=i-1; int x=a[i],xi=i; for(int j=i;j;j=pre[j]) { a[j]=__gcd(a[j],x); ans[a[j]]+=j-pre[j]; if(a[j]

转载地址:http://dkxbl.baihongyu.com/

你可能感兴趣的文章
关于git的一些操作
查看>>
[原]RobotFrameWork(四)变量运算与Evaluate
查看>>
心态决定命运_no excuses, suck it up, obey your teacher
查看>>
【HDOJ】2371 Decode the Strings
查看>>
【HDOJ】1818 It's not a Bug, It's a Feature!
查看>>
java环境变量
查看>>
180510.最近踩过和听过的sql的坑
查看>>
FastSocket学习笔记~RPC的思想,面向对象的灵活
查看>>
TCP连接探测中的Keepalive 和心跳包
查看>>
2015第5周三网摘
查看>>
C#系列教程——对一个对象的装箱取消转换
查看>>
RTP协议分析
查看>>
簡單SQL存儲過程實例
查看>>
有效沟通:听懂话,才能回答(转)
查看>>
整理的代码规范
查看>>
IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结...
查看>>
小知识~让你的DLL类库带上注释
查看>>
Junit测试打印详细的log日志,可以看到sql
查看>>
还是畅通工程
查看>>
什么是Monad?
查看>>