QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87440 | #5503. Euclidean Algorithm | chiranko | TL | 18514ms | 7284kb | C++14 | 1.1kb | 2023-03-12 21:45:42 | 2023-03-12 21:45:45 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define rep(l,r) for(int i=l;i<=r;i++)
#define jrep(l,r) for(int j=l;j<=r;j++)
using namespace std;
typedef __int128 lll;
typedef long long ll;
const int P=500000,N=P+10;
ll ff[N];
bitset<N> st;
ll f(ll n)
{
if(n<=P&&st[n])return ff[n];
ll cnt=n>=2;
ll l=1,r;
n--;
while(l<=n)
{
ll t=n/(double)l;
r=n/(double)t;
cnt+=(r-l+1ll)*(t-1);
l=r+1;
}
if(n<P)
{
st[n+1]=true;
return ff[n+1]=cnt;
}
return cnt;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int T;cin>>T;
while(T--)
{
ll n;cin>>n;
ll ans=0;
ll l=1,r;
while(l<=n>>1)
{
ll t=n/(double)l;
r=min(n>>1,ll(n/(double)t));
ans+=(r-l+1ll)*(t-2);
l=r+1;
}
// cout<<ans<<' ';
l=1;
while(l<=n)
{
ll t=n/(double)l;
r=n/(double)t;
ans+=(r-l+1ll)*f(t);
l=r+1;
}
cout<<ans<<'\n';
}
return 0;
}
/*
3
100000000000
100000000000
100000000000
*/
/*
3
1000000000
1000000000
1000000000
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3468kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 18514ms
memory: 7284kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: -100
Time Limit Exceeded
input:
3 90076809172 100000000000 99913139559
output:
30192292781431 33790187414013