#include<bits/stdc++.h>
const int N=10000001,mod=998244353;
using namespace std;
int hp[N],hc[N];
int to[N][9],t[N],tl,pr[664579];
bitset<N>np;
void ts(int u,int c)
{
for(int i=t[u]++;i>0;--i)
to[u][i]=to[u][i]+1ll*to[u][i-1]*c;
}
int main()
{
np[1]=1,to[1][0]=t[1]=1;
for(int i=1;i<N;++i)
{
if(np[i]==0)
{
pr[tl++]=i;
to[i][0]=t[i]=1,ts(i,hp[i]=1),hc[i]=i;
}
for(int j=0;i*pr[j]<N&&j<tl;++j)
{
if(i*pr[j]>=N)break;
np[i*pr[j]]=1;
if(i%pr[j]==0)
{
hc[i*pr[j]]=hc[i]*pr[j];
int A=i/hc[i];
copy(to[A],to[A]+t[A],to[i*pr[j]]),t[i*pr[j]]=t[A];
ts(i*pr[j],hp[i*pr[j]]=hp[i]+1);
break;
}
copy(to[i],to[i]+t[i],to[i*pr[j]]),t[i*pr[j]]=t[i];
ts(i*pr[j],hp[i*pr[j]]=1),hc[i*pr[j]]=pr[j];
}
}
for(int i=1;i<N;++i)
{
t[i]=max(t[i],t[i-1]);
for(int j=0;j<t[i-1];++j)
to[i][j]+=to[i-1][j];
}
int T;scanf("%d",&T);
while(T--)
{
int n,k,res=0;scanf("%d%d",&n,&k);
for(int i=t[n]-1;i>=0;--i)
res=(1ll*res*k+to[n][i])%mod;
printf("%d\n",res);
}
return 0;
}剪贴板
剪贴板 dw2ij3mf
剪贴板信息
剪贴板信息
- 收录
- 更新