QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#604542 | #8761. 另一个计数问题 | UESTC_NLNS# | WA | 43ms | 41484kb | C++14 | 2.4kb | 2024-10-02 11:57:27 | 2024-10-02 11:57:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define lll __int128
using namespace std;
const int N=1e6+5,M=1e7+5,mod=998244353;
ll cc,sq,cnt,p[M],f[N],tot,w[N],g[N],sum1[N],sum2[N];
int id1[N],id2[N];
bool vis[M];
ll quick_pow(ll x,ll y)
{
ll res=1;
for(;y;y>>=1)
{
if(y&1) res=res*x%mod;
x=x*x%mod;
}
return res;
}
ll inv(ll x){
return quick_pow(x,mod-2);
}
void shai(ll x)
{
cc=0;
for(int i=2;i<=x;i++)
{
if(!vis[i]) p[++cc]=i,(sum1[cc]=sum1[cc-1]+i)%mod,sum2[cc]=(sum2[cc-1]+1ll*i*i%mod)%mod;
for(int j=1;j<=cc&&p[j]*i<=x;j++)
{
vis[i*p[j]]=true;
if(!(i%p[j])) break;
}
}
return;
}
void init(ll x,ll n)
{
tot=0;
cnt=upper_bound(p+1,p+cc+1,x)-p-1;
for(ll l=1,r;l<=n;l=r+1)
{
r=(n/(n/l));
w[++tot]=n/l;
if(n/l<=x) id1[n/l]=tot;
else id2[n/(n/l)]=tot;
}
return;
}
ll n,m,t,o;
int id(ll x) {return x<=sq?id1[x]:id2[o/x];}
void calc_sum()
{
for(int i=1;i<=tot;i++) g[i]=((1ll*(1+w[i])*w[i])%mod*inv(2)%mod+mod-1)%mod;
for(int i=1;i<=cnt;i++)
for(int j=1;j<=tot;j++)
{
if(p[i]*p[i]>w[j]) break;
g[j]-=(g[id(w[j]/p[i])]-sum1[i-1])*p[i]%mod;
g[j]%=mod;
g[j]=(g[j]+mod)%mod;
}
return;
}
void calc_sum2()
{
for(int i=1;i<=tot;i++) g[i]=((w[i])*(w[i]+1)%mod*(w[i]*2+1)%mod*inv(2)%mod+mod-1)%mod;
for(int i=1;i<=cnt;i++)
for(int j=1;j<=tot;j++)
{
if(p[i]*p[i]>w[j]) break;
g[j]-=(g[id(w[j]/p[i])]-sum2[i-1])*p[i]%mod*p[i]%mod;
g[j]%=mod;
g[j]=(g[j]+mod)%mod;
}
return;
}
ll get_sum(ll x)
{
sq=sqrt(x);
init(sq,x);
o=x;
calc_sum();
return g[1];
}
ll get_sum2(ll x)
{
sq=sqrt(x);
init(sq,x);
o=x;
calc_sum2();
return g[1];
}
ll g_sum(ll x){
x%=mod;
return (x*(x+1)%mod*inv(2) - 1 + mod)%mod;
}
ll g_sum2(ll x){
x%=mod;
return (x*(x+1)%mod*(2*x+1)%mod*inv(6)-1 + mod)%mod;
}
int main()
{
// freopen("E.in","r",stdin);
// freopen("E+.out","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
shai(M-1);
ll a1 = (mod + get_sum(n) - get_sum(n/2))%mod;
ll a2 = (mod + get_sum2(n) - get_sum2(n/2))%mod;
ll a3 = g_sum(n);
ll a4 = g_sum2(n);
ll ans = (a3 * a3%mod - a4 + mod)*inv(2) %mod;
ans = (ans - a1 * (a3 - a1)%mod + mod )%mod;
ll a5 = (a1 * a1 %mod - a2 +mod)*inv(2)%mod;
ans = (ans - a5 + mod)%mod;
if(ans<0)ans+=mod;
cout<<ans;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 43ms
memory: 41484kb
input:
4
output:
13
result:
wrong answer 1st numbers differ - expected: '8', found: '13'