题目:
解:神仙 题 化出了式子了 还要会构造函数,构造了函数 还要会实现。 牛逼儿~~~ ( 出处:)
#include#define LL long long#define ULL unsigned long long#define rep(i,j,k) for(int i=j;i<=k;i++)#define dep(i,j,k) for(int i=k;i>=j;i--)#define INF 0x3f3f3f3f#define mem(i,j) memset(i,j,sizeof(i))#define make(i,j) make_pair(i,j)#define pb push_backusing namespace std;const int block=35;const int N=1e5+9;const LL p=998244353;bool vis[N];int mu[N],phi[N],pre[N];int *G[N],*S[block+1][block+1],F[N];int inv[N],tot;void init() { mu[1]=phi[1]=inv[1]=1; rep(i,2,100000) { if(!vis[i]) { pre[++tot]=i; mu[i]=-1; phi[i]=i-1; } rep(j,1,tot) { if(i*pre[j]>100000) break; vis[i*pre[j]]=true; if(i%pre[j]==0) { phi[i*pre[j]]=phi[i]*pre[j]; break; } else { phi[i*pre[j]]=phi[i]*phi[pre[j]]; mu[i*pre[j]]=-mu[i]; } } } rep(i,2,100000) inv[i]=p-1LL*p/i*inv[p%i]%p; rep(i,1,100000) { for(int j=1;j*i<=100000;j++) { F[i*j]=1LL*(1LL*F[i*j]+1LL*i*inv[phi[i]]%p*mu[j]%p)%p; } } rep(i,1,100000) { G[i]=new int [N/i+1]; G[i][0]=0; rep(j,1,100000/i) { G[i][j]=1LL*(1LL*G[i][j-1]+1LL*phi[i*j])%p; } } rep(j,1,block) { rep(k,1,block) { int len(100000/(max(k,j))); S[j][k]=new int [len+1]; S[j][k][0]=0; rep(i,1,len) { S[j][k][i]=1LL*(1LL*S[j][k][i-1]+1LL*F[i]*G[i][j]%p*G[i][k]%p)%p; } } }}LL cal(int n,int m) { if(n>m) swap(n,m); LL ans=0; for(int i=1;i<=m/block;i++) ans=(ans+1LL*F[i]*G[i][n/i]%p*G[i][m/i]%p)%p; for(int l=m/block+1,r;l<=n;l=r+1) { r=min(n/(n/l),m/(m/l)); ans=(ans+1LL*(S[n/l][m/l][r]-S[n/l][m/l][l-1]+p)%p)%p; } return ans;}int main() { init(); int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d %d",&n,&m); printf("%lld\n",cal(n,m)); } return 0;}