QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76821 | #5503. Euclidean Algorithm | Pure_Furies | ML | 0ms | 0kb | C++14 | 818b | 2023-02-12 11:58:40 | 2023-02-12 11:58:43 |
Judging History
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