题意:对于每一次询问,求上式的值
题解:把a排序,由于分母的范围很小 [2,30],可以枚举,对于每一次询问p,枚举分母 i 时,可以找出a中分母等于 i 的那一段,预,
处理前缀和,用于此时直接加。记得要卡内存。。。
如果 1<a[i]<=p ,那么 ceil(log p(a[i])) = 1 。
如果 p<a[i]<=p^2,那么 ceil(log p(a[i])) = 2 。
//#include<cstdio>
//#include<cstring>
//#include<algorithm>
//#include<iostream>
//#include<string>
//#include<vector>
//#include<stack>
//#include<bitset>
//#include<cstdlib>
//#include<cmath>
//#include<set>
//#include<list>
//#include<deque>
//#include<map>
//#include<queue>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1e9+7;
const int mod = 1e9;
ll a[500005],p[500005],sum[31][500005];
int main(){
ll T,n,m;
scanf("%d",&T);
while(T--){
scanf("%lld %lld",&n,&m);
for(int i = 1 ; i <= n ; i++){
scanf("%lld",&a[i]);
}
for(int i = 1 ; i <= m ; i++){
scanf("%lld",&p[i]);
}
sort(a+1,a+1+n);
for(int i = 1 ; i <= 30 ; i++){
for(int j = 1 ; j <= n ; j++){
sum[i][j] = sum[i][j-1]+a[j]/i;
}
}
ll ans = 0;
for(int j = 1 ; j <= m ; j++){
ll ans1 = 0;
ll pp = 1,cnt=1;
for(int pos = 0, pos2 = 0; pp < a[n] ; ++cnt){
pos2 = upper_bound(a+1, a+1+n, pp)-a-1;
pp *= p[j];
pos = upper_bound(a+1, a+1+n, pp)-a-1;
ans1 = (ans1 + (sum[cnt][pos]-sum[cnt][pos2]))%mod;
}
ans = (ans + ans1*j%mod)%mod;
}
printf("%lld\n", (ans+mod)%mod);
}
}