题解:AT_abc414_e [ABC414E] Count A%B=C
fish_love_cat · · 题解
整除分块板子,甚至不需要推导。
刻画合法三元组性质:
当
于是
当
于是
对于任意
满足限制一的组数是可以直接算的。
然后违反限制二的组数可以整除分块一下算出来。
然后做完了。
甚至把 UVA11526 粘过来改改就行。
样例三被卡精度的话记得开 __int128。
#include<bits/stdc++.h>
#define int __int128
#define mod 998244353ll
using namespace std;
int read(){
int sum=0,fish=1;
char c=getchar_unlocked();
while((c<'0'||c>'9')&&c!='-')c=getchar_unlocked();
if(c=='-')fish=-1,c=getchar_unlocked();
while(c>='0'&&c<='9')sum=sum*10+(c-'0'),c=getchar_unlocked();
return sum*fish;
}
void print(int x){
if(x<0)putchar_unlocked('-'),x=-x;
if(x<10)putchar_unlocked(x+'0');
else print(x/10),putchar_unlocked(x%10+'0');
}
void solve(){
int n=read();
int ans=0;
int sq=sqrt((long long)n);
for(int i=1;i<=sq;i++)
ans+=n/i%mod,ans%=mod;
ans*=2;ans%=mod;
ans-=sq*sq%mod;ans=(ans+mod)%mod;
print(((1ll+n)%mod*n%mod*499122177ll%mod-ans+mod)%mod);
}
signed main(){
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}