QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#451248 | #8761. 另一个计数问题 | tarjen | WA | 0ms | 22080kb | C++20 | 5.0kb | 2024-06-23 00:19:29 | 2024-06-23 00:19:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
const int Ny2=(mod+1)/2;
const int Ny6=166374059;
const int N=1e6+10;
namespace Min25_1 {
int prime[N], id1[N], id2[N], flag[N], ncnt, m;
int g[N], sum[N], a[N], T, n;
inline void fff()
{
for(int i=0;i<=N;i++){
prime[i]=0;
id1[i]=0;
id2[i]=0;
flag[i]=0;
g[i]=0;
sum[i]=0;
a[i]=0;
}
ncnt=0;
m=0;
T=0;
n=0;
}
inline int ID(int x) {
return x <= T ? id1[x] : id2[n / x];
}
inline int calc(int x) {
return x * (x + 1)%mod*Ny2%mod; - 1;
}
inline int f(int x) {
return x;
}
inline void init() {
T = sqrt(n + 0.5);
for (int i = 2; i <= T; i++) {
if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + i;
for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
flag[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
for (int l = 1; l <= n; l = n / (n / l) + 1) {
a[++m] = n / l;
if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
g[m] = calc(a[m]);
}
for (int i = 1; i <= ncnt; i++)
for (int j = 1; j <= m && (int)prime[i] * prime[i] <= a[j]; j++)
g[j] = g[j] - ((int)prime[i] * (g[ID(a[j] / prime[i])])%mod - sum[i - 1]),
g[j]=(g[j]+2*mod)%mod;
}
inline int solve(int x) {
if (x <= 1) return x;
return n = x, init(), g[ID(n)];
}
}
namespace Min25_2 {
int prime[N], id1[N], id2[N], flag[N], ncnt, m;
int g[N], sum[N], a[N], T, n;
inline void fff()
{
for(int i=0;i<=N;i++){
prime[i]=0;
id1[i]=0;
id2[i]=0;
flag[i]=0;
g[i]=0;
sum[i]=0;
a[i]=0;
}
ncnt=0;
m=0;
T=0;
n=0;
}
inline int ID(int x) {
return x <= T ? id1[x] : id2[n / x];
}
inline int calc(int x) {
// return x * (x + 1) / 2 - 1;
return x*(x+1)%mod*(x*2+1)%mod*Ny6-1;
}
inline int f(int x) {
return x;
}
inline void init() {
T = sqrt(n + 0.5);
for (int i = 2; i <= T; i++) {
if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + i;
for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
flag[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
for (int l = 1; l <= n; l = n / (n / l) + 1) {
a[++m] = n / l;
if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
g[m] = calc(a[m]);
}
for (int i = 1; i <= ncnt; i++)
for (int j = 1; j <= m && (int)prime[i] * prime[i] <= a[j]; j++)
g[j] = g[j] - (int)prime[i]*prime[i]%mod * (g[ID(a[j] / prime[i])] - sum[i - 1]),
g[j]=(g[j]+2*mod)%mod;
}
inline int solve(int x) {
if (x <= 1) return x;
return n = x, init(), g[ID(n)];
}
}
// typedef long double lf;
// int Mod(int x){
// long double z=(lf)x/mod;
// x-=(int)z*mod;
// return x;
// }
// const int maxn=1e6+10;
// int pr[maxn],prs[maxn],prs2[maxn]=0,f[maxn];
// void add(int &x,int y){
// if((x+=y)>=mod)x-=mod;
// }
// void del(int &x,int y){
// if((x-=y)<0)x+=mod;
// }
int Sum(int x){
x%=mod;
return x*(x+1)%mod*Ny2%mod;
}
// map<pair<int,int>,int> ma,ma2;
// int S(int x,int m){
// while(pr[m]*pr[m]>x)m--;
// if(m==0)return Mod(Sum(x)-1+mod);
// if(ma.find({x,m})!=ma.end())return ma[{x,m}];
// int res=Mod(Sum(x)-1+mod);
// for(int i=1;i<=m;i++){
// del(res,Mod(pr[i]*(Mod(S(x/pr[i],i-1)-prs[i-1]+mod))));
// }
// return ma[{x,m}]=res;
// }
int Sum2(int x){
x%=mod;
return x*(x+1)%mod*(x*2+1)%mod*Ny6%mod;
// return Mod(Mod(Mod(x*(x+1))*(2*x+1))*Ny6);
}
// int S2(int x,int m){
// while(pr[m]*pr[m]>x)m--;
// if(m==0)return Mod(Sum2(x)-1+mod);
// if(ma2.find({x,m})!=ma2.end())return ma2[{x,m}];
// int res=Mod(Sum2(x)-1+mod);
// for(int i=1;i<=m;i++){
// del(res,Mod(Mod(pr[i]*pr[i])*(Mod(S2(x/pr[i],i-1)-prs2[i-1]+mod))));
// }
// return ma2[{x,m}]=res;
// }
int S(int x){
return Min25_1::solve(x);
}
int S2(int x){
return Min25_2::solve(x);
}
signed main()
{
int n;cin>>n;
int p1=(S(n)-S(n/2)+mod)%mod;
int p2=(S2(n)-S2(n/2)+mod)%mod;
int z=(Sum(n)-1)*(Sum(n)-1)%mod;
// cout<<"z="<<z<<" p1="<<p1<<" p2="<<p2<<endl;
z=(z-(Sum(n)-1)*p1%mod-(Sum(n)-1-p1)*p1%mod+2*mod)%mod;
// cout<<"z="<<z<<endl;
z=(z+p2)%mod;
z=(z-(Sum2(n)-1)+mod)%mod;
z=z*Ny2%mod;
cout<<z;
// int ans=0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22080kb
input:
4
output:
22
result:
wrong answer 1st numbers differ - expected: '8', found: '22'