http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5480
数学题,用GCD做。用到容斥的知识。感谢LinXI的博客
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
long long num[1000010];
long long g[2000010];
long long f[2000010];
long long make_pow(long long x,long long n,long long mod)
{
long long res =1;
while(n>0)
{
if(n&1)res = res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
int main()
{
long long T;
cin >> T;
while(T--)
{
long long n,k;
cin >> n >> k;
long long maxn=-1;
memset(g,0,sizeof(g));
for(int i=0;i<n;i++)
{
cin >> num[i];
g[num[i]]++;
maxn = max(maxn,num[i]);
}
for(int i = maxn;i>=1;i--)
{
long long sum=0;
f[i]=0;
for(int j = i;j<=maxn;j+=i)
{
sum+=g[j];
f[i]=(f[i]-f[j]+998244353)%998244353;
}
f[i]=(f[i]+make_pow(2,sum,998244353)-1)%998244353;
}
long long ans = 0;
for(int i=1;i<=maxn;i++)
{
ans=(ans+((make_pow(i,k,998244353))*(f[i]))%998244353)%998244353;
}
cout<<ans<<endl;
}
return 0;
}