QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604562#8761. 另一个计数问题UESTC_NLNS#AC ✓1903ms57532kbC++142.4kb2024-10-02 12:03:352024-10-02 12:03:36

Judging History

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

  • [2024-10-02 12:03:36]
  • 评测
  • 测评结果:AC
  • 用时:1903ms
  • 内存:57532kb
  • [2024-10-02 12:03:35]
  • 提交

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;x%=mod;
	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])%mod*(w[i]%mod))%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]%mod)*(w[i]%mod+1)%mod*(w[i]%mod*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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 39ms
memory: 40528kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 31ms
memory: 43716kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

score: 0
Accepted
time: 42ms
memory: 39848kb

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

score: 0
Accepted
time: 45ms
memory: 42292kb

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

score: 0
Accepted
time: 42ms
memory: 39876kb

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

score: 0
Accepted
time: 34ms
memory: 42480kb

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

score: 0
Accepted
time: 51ms
memory: 43632kb

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

score: 0
Accepted
time: 48ms
memory: 42592kb

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

score: 0
Accepted
time: 28ms
memory: 41364kb

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

score: 0
Accepted
time: 45ms
memory: 42844kb

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

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

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

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

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 121ms
memory: 42628kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

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

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 121ms
memory: 44108kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 126ms
memory: 43628kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

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

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 186ms
memory: 44160kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 244ms
memory: 43904kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 474ms
memory: 51052kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 575ms
memory: 45520kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: 0
Accepted
time: 871ms
memory: 50916kb

input:

31326230483

output:

99981147

result:

ok 1 number(s): "99981147"

Test #40:

score: 0
Accepted
time: 895ms
memory: 47700kb

input:

32810385543

output:

284259680

result:

ok 1 number(s): "284259680"

Test #41:

score: 0
Accepted
time: 979ms
memory: 50676kb

input:

37368395332

output:

511468046

result:

ok 1 number(s): "511468046"

Test #42:

score: 0
Accepted
time: 1035ms
memory: 49592kb

input:

40002331093

output:

282851705

result:

ok 1 number(s): "282851705"

Test #43:

score: 0
Accepted
time: 1660ms
memory: 52364kb

input:

82884464396

output:

767050832

result:

ok 1 number(s): "767050832"

Test #44:

score: 0
Accepted
time: 1828ms
memory: 55004kb

input:

96506992785

output:

31413975

result:

ok 1 number(s): "31413975"

Test #45:

score: 0
Accepted
time: 1879ms
memory: 52252kb

input:

99999999995

output:

456189842

result:

ok 1 number(s): "456189842"

Test #46:

score: 0
Accepted
time: 1871ms
memory: 54924kb

input:

99999999996

output:

516138273

result:

ok 1 number(s): "516138273"

Test #47:

score: 0
Accepted
time: 1880ms
memory: 56376kb

input:

99999999997

output:

136420410

result:

ok 1 number(s): "136420410"

Test #48:

score: 0
Accepted
time: 1875ms
memory: 54536kb

input:

99999999998

output:

841974696

result:

ok 1 number(s): "841974696"

Test #49:

score: 0
Accepted
time: 1903ms
memory: 57532kb

input:

99999999999

output:

164762165

result:

ok 1 number(s): "164762165"

Test #50:

score: 0
Accepted
time: 1878ms
memory: 55108kb

input:

100000000000

output:

627965619

result:

ok 1 number(s): "627965619"