QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76814 | #5503. Euclidean Algorithm | zhouhuanyi | TL | 29783ms | 7488kb | C++11 | 954b | 2023-02-12 11:42:54 | 2023-02-12 11:42:58 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 1000000
using namespace std;
long long read()
{
long long sum=0;
char c=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,d[N+1];
long long n;
__int128 ans;
__int128 C2(long long x)
{
return ((__int128)(x)*(x-1))>>1;
}
__int128 F(long long x)
{
if (x<=N) return d[x];
__int128 res=0;
for (long long i=1,lst;i<=x;i=lst+1) lst=x/(x/i),res+=(x/i)*(lst-i+1);
return res;
}
void write(__int128 x)
{
if (!x) return;
write(x/10),printf("%d",(int)(x%10));
return;
}
int main()
{
T=read();
for (int i=1;i<=N;++i)
for (int j=i;j<=N;j+=i)
d[j]++;
for (int i=1;i<=N;++i) d[i]+=d[i-1];
while (T--)
{
n=read(),ans=0;
for (long long i=1,lst;i<=n;i=lst+1) lst=n/(n/i),ans+=F(n/i-1)*(lst-i+1);
write(ans),puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 27ms
memory: 7436kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 14441ms
memory: 7440kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 29783ms
memory: 7488kb
input:
3 90076809172 100000000000 99913139559
output:
30192292781431 33790187414013 33758574429172
result:
ok 3 lines
Test #4:
score: -100
Time Limit Exceeded
input:
3 99997992652 99832769119 99997176887