QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87420#5503. Euclidean Algorithmchiranko#TL 3ms3380kbC++14817b2023-03-12 20:47:462023-03-12 20:47:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-12 20:47:46]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3380kb
  • [2023-03-12 20:47:46]
  • 提交

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;

lll f(ll n)
{
	lll cnt=n>=2;
	ll l=1,r;
	n--;
	while(l<=n)
	{
		r=n/(n/l);
		cnt+=(lll)(r-l+1ll)*(n/l-1);
		l=r+1;
	}
	return cnt;
}

void print(lll 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;
		lll ans=0;
		ll l=1,r;
		while(l<=n>>1)
		{
			r=min(n>>1,n/(n/l));
			ans+=(lll)(r-l+1ll)*(n/l-2);
			l=r+1;
		}
		// cout<<ans<<' ';
		l=1;
		while(l<=n)
		{
			r=n/(n/l);
			ans+=(lll)(r-l+1ll)*f(n/l);
			l=r+1;
		}
		print(ans);
		cout<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3380kb

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

output:

8921593237533
21300450379732

result: