QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77689 | #5503. Euclidean Algorithm | chenshi# | ML | 0ms | 0kb | C++ | 555b | 2023-02-15 13:02:18 | 2023-02-15 13:02:20 |
Judging History
answer
#include<cstdio>
using namespace std;
const int o=1.7e6;
int z,v[o];long long n,ans;
inline long long sd(long long n){
if(n<o) return v[n];
long long res=0;
for(long long i=1,j,t;i<=n;i=j+1) j=n/(t=n/i),res+=t*(j-i+1ll);
return res;
}
int main(){
for(int i=1;i<o;++i) for(int j=i;j<o;j+=i) ++v[j];
for(int i=1;i<o;++i) v[i]+=v[i-1];
for(scanf("%d",&z);z--;printf("%lld\n",ans),ans=0){
scanf("%lld",&n);
ans=sd(n)-n;
for(long long i=2,j,lst=0,t;i<=n;i=j+1) j=n/(n/i),t=sd(j-1),ans+=n/i*(t-lst-(j-i+1)),lst=t;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 5 14
output:
1 9 62