QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87429#5503. Euclidean Algorithmchiranko#WA 2ms3372kbC++141.1kb2023-03-12 21:16:332023-03-12 21:16:37

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 21:16:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3372kb
  • [2023-03-12 21:16:33]
  • 提交

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 N=1e6+10,P=500000;

ll ff[N];
bool st[N];

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/l;
		r=n/t;
		cnt+=(r-l+1ll)*(t-1);
		l=r+1;
	}
	if(n<=P)
	{
		st[n]=true;
		return ff[n]=cnt;
	}
	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)
		{
			ll t=n/l;
			r=min(n>>1,n/t);
			ans+=(r-l+1ll)*(t-2);
			l=r+1;
		}
		// cout<<ans<<' ';
		l=1;
		while(l<=n)
		{
			ll t=n/l;
			r=n/t;
			ans+=(r-l+1ll)*f(t);
			l=r+1;
		}
		cout<<ans<<'\n';
	}
	return 0;
}

/*
3
100000000000
100000000000
100000000000
*/
/*
3
1000000000
1000000000
1000000000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3372kb

input:

3
2
5
14

output:

2
12
74

result:

wrong answer 1st lines differ - expected: '1', found: '2'