In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has n different species of flowers he can plant, with ai flowers of the i-th species.

On each of the next q days, Farmer John will receive a batch of flowers of a new species. On day j, he will receive cj flowers of the same species, but of a different species from those Farmer John already has.

Farmer John, knowing the right balance between extravagance and minimalism, wants exactly k species of flowers to be used. Furthermore, to reduce waste, each flower of the k species Farmer John chooses must be planted in some garden. And each of the gardens must be identical; that is to say that each of the k chosen species should have an equal number of flowers in each garden. As Farmer John is a proponent of national equality, he would like to create the greatest number of gardens possible.

After receiving flowers on each of these q days, Farmer John would like to know the sum, over all possible choices of k species, of the maximum number of gardens he could create. Since this could be a large number, you should output your result modulo 109 + 7.

Input

The first line of the input contains three integers n, k and q (1 ≤ k ≤ n ≤ 100 000, 1 ≤ q ≤ 100 000).

The i-th (1 ≤ i ≤ n) of the next n lines of the input contains an integer ai (1 ≤ ai ≤ 1 000 000), the number of flowers of species i Farmer John has initially.

The j-th (1 ≤ j ≤ q) of the next q lines of the input contains an integer cj (1 ≤ cj ≤ 1 000 000), the number of flowers of a new species Farmer John receives on day j.

Output

After each of the q days, output the sum of the maximum possible number of gardens, where the sum is taken over all possible choices of k species, modulo 109 + 7.

Examples

Input
3 3 2
4
6
9
8
6
Output
5
16
Input
4 1 2
6
5
4
3
2
1
Output
20
21

Note

In the first sample case, after the first day Farmer John has (4, 6, 9, 8) of each type of flower, and k = 3.

Choosing (4, 6, 8) lets him make 2 gardens, each with (2, 3, 4) of each flower, respectively. Choosing (4, 6, 9), (4, 9, 8) and (6, 9, 8) each only let him make one garden, since there is no number of gardens that each species can be evenly split into. So the sum over all choices of k = 3 flowers is 2 + 1 + 1 + 1 = 5.

After the second day, Farmer John has (4, 6, 9, 8, 6) of each flower. The sum over all choices is 1 + 2 + 2 + 1 + 1 + 2 + 2 + 3 + 1 + 1 = 16.

In the second sample case, k = 1. With x flowers Farmer John can make x gardens. So the answers to the queries are 6 + 5 + 4 + 3 + 2 = 20 and 6 + 5 + 4 + 3 + 2 + 1 = 21.

题意:给出N个初始的数,M个新加的数,以及K,求出每次新加一个数后,所有K元组的gcd之和。

思路:每次新加一个数x,我们在之前的答案基础上只考虑新加的这个数x和之前的K-1组合起来的gcd。其gcd肯定的x的因子,我们枚举x的因子f,统计之前的出现的含有这个因子f的个数,那么其贡献为C(num[f],K-1)*f。但是这样会出现重复,我们需要去重,这里可以考虑莫比乌斯,最后求出来每个f的系数应该是phi[f]。

莫比乌斯求的过程:我们设d的系数为g[d],那么g[d]=i-Σg[i](i是d且小于d的因子) ,可以线性筛出来,发现就是欧拉函数。

( 曲同工的题:求两两gcd之和  https://www.cnblogs.com/hua-dong/p/9905846.html

求互质对个数:https://www.cnblogs.com/hua-dong/p/9141249.html

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const int Mod=1e9+;
int vis[maxn],p[maxn],phi[maxn],num[maxn],cnt,ans,K;
int fac[maxn],rev[maxn];
int qpow(int a,int x){
int res=; while(x){
if(x&) res=1LL*res*a%Mod;
x>>=; a=1LL*a*a%Mod;
} return res;
}
void init()
{
fac[]=rev[]=;
for(int i=;i<maxn;i++) fac[i]=1LL*fac[i-]*i%Mod;
rev[maxn-]=qpow(fac[maxn-],Mod-);
for(int i=maxn-;i>=;i--) rev[i]=1LL*rev[i+]*(i+)%Mod;
phi[]=;
for(int i=;i<maxn;i++){
if(!vis[i]) p[++cnt]=i,phi[i]=i-;
for(int j=;j<=cnt&&i*p[j]<maxn;j++){
vis[i*p[j]]=;
if(!(i%p[j])){phi[i*p[j]]=phi[i]*p[j]; break;}
phi[i*p[j]]=phi[i]*(p[j]-);
}
}
}
int C(int N,int M)
{
if(N<M) return ;
return 1LL*fac[N]*rev[M]%Mod*rev[N-M]%Mod;
}
void add(int x)
{
for(int i=;i*i<=x;i++){
if(x%i==){
ans=(ans+1LL*C(num[i],K-)*phi[i]%Mod)%Mod;
if(i*i!=x) ans=(ans+1LL*C(num[x/i],K-)*phi[x/i]%Mod)%Mod;
}
}
for(int i=;i*i<=x;i++){
if(x%i==){
num[i]++;
if(i*i!=x) num[x/i]++;
}
}
}
int main()
{
int N,Q,x;
init();
scanf("%d%d%d",&N,&K,&Q);
rep(i,,N) {
scanf("%d",&x);
add(x);
}
rep(i,,Q){
scanf("%d",&x);
add(x);
printf("%d\n",ans);
}
return ;
}

CodeForces - 645F:Cowslip Collections (组合数&&欧拉函数)的更多相关文章

  1. Codeforces 906D Power Tower(欧拉函数 + 欧拉公式)

    题目链接  Power Tower 题意  给定一个序列,每次给定$l, r$ 求$w_{l}^{w_{l+1}^{w_{l+2}^{...^{w_{r}}}}}$  对m取模的值 根据这个公式 每次 ...

  2. Codeforces 1114F Please, another Queries on Array? [线段树,欧拉函数]

    Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)= ...

  3. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  4. Codeforces 871D Paths (欧拉函数 + 结论)

    题目链接  Round  #440  Div 1  Problem D 题意   把每个数看成一个点,如果$gcd(x, y) \neq 1$,则在$x$和$y$之间连一条长度为$1$的无向边.   ...

  5. Codeforces 1114F(欧拉函数、线段树)

    AC通道 要点 欧拉函数对于素数有一些性质,考虑将输入数据唯一分解后进行素数下的处理. 对于素数\(p\)有:\(\phi(p^k)=p^{k-1}*(p-1)=p^k*\frac{p-1}{p}\) ...

  6. Please, another Queries on Array?(Codeforces Round #538 (Div. 2)F+线段树+欧拉函数+bitset)

    题目链接 传送门 题面 思路 设\(x=\prod\limits_{i=l}^{r}a_i\)=\(\prod\limits_{i=1}^{n}p_i^{c_i}\) 由欧拉函数是积性函数得: \[ ...

  7. Codeforces 776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

  8. codeforces 1009D Relatively Prime Graph【欧拉函数】

    题目:戳这里 题意:要求构成有n个点,m条边的无向图,满足每条边上的两点互质. 解题思路: 显然1~n这n个点能构成边的条数,就是2~n欧拉函数之和(x的欧拉函数值代表小于x且与x互质的数的个数. 因 ...

  9. HDU 4483 Lattice triangle(欧拉函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情 ...

随机推荐

  1. RabbitMQ入门_06_深入了解ack

    A. Delivery Tag 参考资料:https://www.rabbitmq.com/confirms.html 仔细查看一下 Consumer 的回调方法: public void handl ...

  2. javascript对象使用总结

    javascript对象使用总结 一.总结 一句话总结:js对象的主要知识点是创建对象和继承,并且创建对象和继承的方法都是逐步层层递进的 创建对象 继承 原型 创建对象 1 <script> ...

  3. 转发一篇分析LinQ是什么?

    LINQ(发音:Link)是语言级集成查询(Language INtegrated Query) ?LINQ是一种用来进行数据访问的编程模型,使得.NET语言可以直接支持数据查询 ?LINQ的目标是降 ...

  4. arcgis for silverlight 地图放大到某个点或者几何对象

    http://blog.csdn.net/xuan444150/article/details/7727866   分类: silverlight王国 GIS王国 2012-07-09 08:50 1 ...

  5. codeforces 578b//"Or" Game// Codeforces Round #320 (Div. 1)

    题意:n个数字,最多操作k次,每次乘x,要使结果数组的与值最大. 能推断出结果是对一个元素操作k次,并且这个元素的二进制最高位比较大.并不一定是取最大的,比如1100和1010,乘以一次2,两种选法分 ...

  6. 在centos7上安装gcc、node.js(源码下载)

    一.在centos7中安装node.js https://www.cnblogs.com/lpbottle/p/7733397.html 1.从源码下载Nodejs cd /usr/local/src ...

  7. Oracle11g温习-第一章 1、ORACLE实例

    2013年4月27日 星期六 10:23 1.ORACLE 实例 System Global Area(SGA) 和 Background Process(后台进程) 称为数据库的实例. 2.ORAC ...

  8. BZOJ一天提交(AC) 51纪念

    像我这种蒟蒻...一天交了51道题也要纪念... 真是...但是.不知道还有没有机会了... 这样子就会有很多题解要补了...慢慢来吧... 另.AC数已经超过500了还真是历史性的一步啊...

  9. html <form>相关表单

    action属性规定提交表单时,向何处发送表单数据 radio 分组 只要name一样,就是一组,即一组中只能选择一个. <input type="radio" id=&qu ...

  10. Gradle 完整指南(Android)

    Gradle 的编译周期 在解析 Gradle 的编译过程之前我们需要理解在 Gradle 中非常重要的两个对象.Project和Task. 每个项目的编译至少有一个 Project,一个 build ...