QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#76821#5503. Euclidean AlgorithmPure_FuriesML 0ms0kbC++14818b2023-02-12 11:58:402023-02-12 11:58:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-12 11:58:43]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-02-12 11:58:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1500000;
int T,f[N+3];
long long calc(long long n){
	if(n<=N)return f[n];
	long long l=1,r,ret=0,t,sq=sqrt(n);
	while(l<=n){
		t=n/l;
		r=(l<=sq?l:n/t);
		ret+=(r-l+1)*t;
		l=r+1;
	}
	return ret;
}
int main(){
	f[1]=1;
	for(int i=2;i<=N;i++)
		if(!f[i])
			for(int j=i+i;j<=N;j+=i)
				f[j]=i;
	for(int i=2;i<=N;i++)
		if(!f[i])
			f[i]=2;
		else{
			int t=i,c=1;
			while(t%f[i]==0)t/=f[i],c++;
			f[i]=c*f[t];
		}
	for(int i=2;i<=N;i++)
		f[i]+=f[i-1];
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--){
		long long l=1,r,n,t,sq;
		cin>>n;sq=sqrt(n);
		long long ans=0;
		while(l<=n){
			t=n/l;
			r=(l<=sq?l:n/t);
			ans=ans+(r-l+1)*calc(t-1);
			l=r+1;
		}
		cout<<ans<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

3
2
5
14

output:


result: