Edward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, x2,…,xm} (each nonempty subset has equal probability to be picked), and would like to know the expectation of [gcd(x1, x2,…,xm)]k.
Note that gcd(x1, x2,…,xm) is the greatest common divisor of {x1, x2,…,xm}.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains two integers n, k (1 ≤ n, k ≤ 106). The second line contains n integers a1, a2,…,an (1 ≤ ai ≤ 106).
The sum of values max{ai} for all the test cases does not exceed 2000000.
Output
For each case, if the expectation is E, output a single integer denotes E · (2n - 1) modulo 998244353.
Sample Input
1 5 1 1 2 3 4 5
Sample Output
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
using namespace std;
typedef long long LL;
#define maxn (2000005)
#define MOD 998244353
int n,k,seq[maxn];
int dp[maxn],sum[maxn];
int Max;
long long Pow(long long x,long long kk)//快速幂模板
{
long long result=1;
while(kk)
{
if(kk&1) result=result*x%MOD;
x=x*x%MOD;
kk>>=1;
}
return result%MOD;
}//问题出现在数据范围上。。。
//取得模是超出整数范围的。。。(汗)
int main()
{
int t;scanf("%d",&t);
while(t--)
{
memset(sum,0,sizeof(sum));
Max=0;
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++)
{
scanf( "%d",&seq[i] );
Max=max(Max,seq[i]);
sum[seq[i]]++;
}
long long ans=0;
for(long long i=0;i<=Max;i++) dp[i]=0;
for(long long i=Max;i>=1;i--)
{
long long tmp=0;
for(long long j=i;j<=Max;j+=i)
tmp+=sum[j];
// dp[i]=(dp[i]-dp[j]+MOD)%MOD;
dp[i]=((dp[i]+Pow(2,tmp)-1)%MOD+MOD)%MOD;
for(long long j=2*i;j<=Max;j+=i)
dp[i]=(dp[i]-dp[j]+MOD)%MOD;//注意dp数组的时间性很重要(尤其是一维数组,一定要找准过去利用的状态和现在加工的状态)
ans=(ans+dp[i]*Pow(i,k))%MOD;
}//容斥定理用dp思想实现。
cout<<ans<<endl;
}
return 0;
}