QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#87442 | #5503. Euclidean Algorithm | chiranko | TL | 2ms | 3268kb | C++11 | 838b | 2023-03-12 21:52:43 | 2023-03-12 21:52:46 |
Judging History
answer
#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 N=1e6+10;
ll f(ll n)
{
ll cnt=n>=2;
ll l=1,r;
n--;
while(l<=n)
{
r=n/(double)(n/(double)l);
cnt+=(r-l+1ll)*(n/(double)l-1);
l=r+1;
}
return cnt;
}
void print(ll x)
{
if(x>9)print(x/10);
putchar(x%10+'0');
}
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)
{
r=min(n>>1,n/(n/l));
ans+=(r-l+1ll)*(n/l-2);
l=r+1;
}
// cout<<ans<<' ';
l=1;
while(l<=n)
{
r=n/(double)(n/(double)l);
ans+=(r-l+1ll)*f(n/(double)l);
l=r+1;
}
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3268kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
3 29107867360 65171672278 41641960535