QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604549#8761. 另一个计数问题UESTC_NLNS#WA 239ms45228kbC++142.4kb2024-10-02 12:00:092024-10-02 12:00:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 12:00:09]
  • 评测
  • 测评结果:WA
  • 用时:239ms
  • 内存:45228kb
  • [2024-10-02 12:00:09]
  • 提交

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(6)%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: 100
Accepted
time: 36ms
memory: 41964kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 41ms
memory: 44844kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 44ms
memory: 43912kb

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

score: 0
Accepted
time: 40ms
memory: 45064kb

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

score: 0
Accepted
time: 47ms
memory: 43212kb

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

score: 0
Accepted
time: 36ms
memory: 42952kb

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

score: 0
Accepted
time: 47ms
memory: 41308kb

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

score: 0
Accepted
time: 39ms
memory: 41100kb

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

score: 0
Accepted
time: 44ms
memory: 42996kb

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

score: 0
Accepted
time: 39ms
memory: 40068kb

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

score: 0
Accepted
time: 39ms
memory: 41632kb

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

score: 0
Accepted
time: 43ms
memory: 39632kb

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

score: 0
Accepted
time: 39ms
memory: 43368kb

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

score: 0
Accepted
time: 35ms
memory: 42220kb

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

score: 0
Accepted
time: 40ms
memory: 43140kb

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

score: 0
Accepted
time: 43ms
memory: 43720kb

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

score: 0
Accepted
time: 44ms
memory: 42112kb

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

score: 0
Accepted
time: 39ms
memory: 40160kb

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

score: 0
Accepted
time: 40ms
memory: 41276kb

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

score: 0
Accepted
time: 53ms
memory: 43164kb

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

score: 0
Accepted
time: 38ms
memory: 44768kb

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

score: 0
Accepted
time: 41ms
memory: 45132kb

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

score: 0
Accepted
time: 32ms
memory: 45112kb

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

score: 0
Accepted
time: 32ms
memory: 41284kb

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

score: 0
Accepted
time: 36ms
memory: 41624kb

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

score: 0
Accepted
time: 41ms
memory: 42164kb

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

score: 0
Accepted
time: 44ms
memory: 39636kb

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 127ms
memory: 43900kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 131ms
memory: 43128kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 124ms
memory: 43584kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

score: 0
Accepted
time: 125ms
memory: 42412kb

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 122ms
memory: 42468kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 125ms
memory: 41704kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 130ms
memory: 41716kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 181ms
memory: 45228kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: -100
Wrong Answer
time: 239ms
memory: 43684kb

input:

3550627266

output:

694331946

result:

wrong answer 1st numbers differ - expected: '318019384', found: '694331946'