QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432925#8761. 另一个计数问题qzezWA 0ms17964kbC++142.2kb2024-06-07 20:41:252024-06-07 20:41:26

Judging History

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

  • [2024-06-07 20:41:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:17964kb
  • [2024-06-07 20:41:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=sqrt(1e11)+5,M=N*2,mod=998244353;
ll n;
struct node{
	int x,y;
	node(int a=0,int b=0):x(a),y(b){}
};
#ifdef DEBUG
ostream& operator << (ostream &out,node a){
	return out<<make_pair(a.x,a.y);
}
#endif
node operator + (const node &a,const node &b){
	return node((a.x+b.x)%mod,(a.y+b.y)%mod);
}
node operator - (const node &a,const node &b){
	return node((a.x+mod-b.x)%mod,(a.y+mod-b.y)%mod);
}
node operator * (const node &a,const node &b){
	return node(1ll*a.x*b.x%mod,1ll*a.y*b.y%mod);
}
int cnt,pri[N],vis[N];
node pre[N];
void init(int n){
	fill(vis,vis+1+n,0),cnt=0;
	for(int i=2;i<=n;i++){
		if(!vis[i])pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<=n;j++){
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)break;
		}
	}
	for(int i=1;i<=cnt;i++){
		pre[i]=pre[i-1]+node(pri[i],1ll*pri[i]*pri[i]%mod);
	}
}
node f[M];
ll val[M];
int k,id1[N],id2[N];
int getid(ll x){
	if(x*x<=n)return id1[x];
	else return id2[n/x];
}
int sum1(ll x){
	x%=mod;
	return x*(x+1)/2%mod;
}
int sum2(ll x){
	x%=mod;
	return x*(x+1)%mod*(x+x+1)%mod*((mod+1)/6)%mod;
}
node calc(ll n){
	::n=n;
	if(!n)return node();
	init(sqrtl(n)),k=0;
	for(ll l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		ll x=n/l;
		if(x<=n/x)val[id1[x]=++k]=x;
		else val[id2[n/x]=++k]=x;
	}
	for(int i=1;i<=k;i++)f[i]=node(sum1(val[i])-1,sum2(val[i])-1);
	// debug(ary(val,1,k));
	// debug(ary(f,1,k));
	// debug(cnt,ary(pri,1,cnt));
	for(int i=1;i<=cnt;i++){
		node x=node(pri[i],1ll*pri[i]*pri[i]%mod);
		for(int j=1;j<=k&&val[j]>=pri[i];j++){
			f[j]=f[j]-x*f[getid(val[j]/pri[i])]+x*pre[i-1];
		}
		// debug(ary(f,1,k),x,pre[i-1]);
	}
	debug("calc",n,f[getid(n)]);
	return f[getid(n)];
}
int main(){
	ll n;
	cin>>n;
	// debug(n,getid(n));
	// debug(f[getid(n)]);
	node res=calc(n)-calc(n/2);
	int sum=(sum1(n)-1-res.x+mod)%mod;
	int ans=(sum2(n)-1-res.y+mod)%mod;
	ans=(1ll*sum*sum+mod-ans)%mod*((mod+1)/2)%mod;
	cout<<ans<<endl;
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15928kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 15916kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 0ms
memory: 15916kb

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

score: 0
Accepted
time: 0ms
memory: 17964kb

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

score: 0
Accepted
time: 0ms
memory: 15884kb

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

score: 0
Accepted
time: 0ms
memory: 13976kb

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

score: 0
Accepted
time: 0ms
memory: 13964kb

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 13940kb

input:

79

output:

3493623

result:

wrong answer 1st numbers differ - expected: '3224298', found: '3493623'