设 d ( n ) = ∑ i = 1 n [ n m o d i = 0 ] , s ( n ) = ∑ i = 1 n n i d(n)=\sum\limits_{i=1}^n[n\mod i=0],s(n)=\sum\limits_{i=1}^n\frac{n}{i} d(n)=i=1∑n[nmodi=0],s(n)=i=1∑nin
a n s = ∑ i = 1 n ∑ j ∣ m d ( i j ) = ∑ i = 1 n ∑ j ∣ m ∑ x ∣ i ∑ y ∣ j [ ( x , y ) = 1 ] ans=\sum\limits_{i=1}^n \sum\limits_{j|m}d(ij)=\sum\limits_{i=1}^n \sum\limits_{j|m}\sum\limits_{x|i}\sum\limits_{y|j}[(x,y)=1] ans=i=1∑nj∣m∑d(ij)=i=1∑nj∣m∑x∣i∑y∣j∑[(x,y)=1]
考虑先枚举 ( x , y ) (x,y) (x,y)得:
a n s = ∑ i = 1 n ∑ j ∣ m [ ( i , j ) = 1 ] ⌊ n i ⌋ d ( m j ) ans=\sum\limits_{i=1}^n\sum\limits_{j|m}[(i,j)=1]\lfloor \frac{n}{i}\rfloor d(\frac{m}{j}) ans=i=1∑nj∣m∑[(i,j)=1]⌊in⌋d(jm)
a n s = ∑ i = 1 n ∑ j ∣ m ∑ q ∣ g c d ( i , j ) μ ( q ) ⌊ n i ⌋ d ( m j ) ans=\sum\limits_{i=1}^n\sum\limits_{j|m} \sum\limits _{q|gcd(i,j)}\mu(q)\lfloor \frac{n}{i}\rfloor d(\frac{m}{j}) ans=i=1∑nj∣m∑q∣gcd(i,j)∑μ(q)⌊in⌋d(jm)
考虑先枚举 q q q:
a n s = ∑ q ∣ m μ ( q ) s ( n q ) ∑ q ∣ x , x ∣ m d ( m x ) ans=\sum\limits_{q|m}\mu(q) s(\frac{n}{q}) \sum\limits_{q|x,x|m}d(\frac{m}{x}) ans=q∣m∑μ(q)s(qn)q∣x,x∣m∑d(xm)
由于莫比乌斯函数的性质,我们只需要枚举所有莫比乌斯函数非零的因子d(即质因子最高幂次为1)。
s s s函数的答案可以分块计算。
而后半部分的因子个数和可以在dfs的过程中计算出来。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
LL n;
int m;
const int mod=998244353;
LL cal(LL x){
LL y=0;
for(LL i=1,j;i<=x;i=j+1){
j=min(x,x/(x/i));
y+=(j-i+1)%mod*(x/i)%mod;
y%=mod;
}
return y;
}
vector<pair<int,int>>pr;
LL ans;
void dfs(int now,int mu,LL val,LL d,LL oh){
if(now==pr.size()){
ans+=mu*cal(n/d)%mod*val%mod*oh%mod;
ans%=mod;
return;
}
//不选这个数
dfs(now+1,mu,val,d,oh*((pr[now].second+2)*(pr[now].se+1)/2)%mod);
if(d*pr[now].fi<=n){//选这个数
dfs(now+1,-mu,val*((pr[now].second+1)*(pr[now].se)/2)%mod,d*pr[now].fi,oh);
}
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
auto is_pr =[&](int x){
for(int i=2;i<x;i++){
if(x%i==0)return 0;
}
return 1;
};
for(int i=2;i<=m;i++){
if(is_pr(i)){
int z=m,q=0;
while(z){
q+=z/i;
z/=i;
}
pr.pb({i,q});
}
}
dfs(0,1,1,1,1);
cout<<ans<<'\n';
return 0;
}