QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419176#8111. CoachesIratisTL 0ms0kbC++141.5kb2024-05-23 18:27:502024-05-23 18:28:06

Judging History

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

  • [2024-05-23 18:28:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-23 18:27:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define i28 __int128
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)

bool ST;

int n,a,b,lcm,A,B,C,ans;
inline i28 F(int n,int a,int b,int c)
{
	if(a>=c||b>=c)return (i28)n*(n+1)/2*(a/c)+(n+1)*(b/c)+F(n,a%c,b%c,c);
	int L=(a*n+b)/c;return (i28)n*L-F(L-1,c,c-b-1,a);
}
inline bool check(int mid)
{
	i28 P=F(mid,b,b-A+a-1,a),Q=F(mid,b,B-A+a-1,a);
	return P>Q;
}
inline bool saf()
{
	// cout<<A<<" "<<B<<" "<<C<<" "<<a<<" "<<b<<'\n';
	if(B>C)return 0;int l=0,r=(C-B)/b,mid,ans=-1;
	while(l<=r){mid=(l+r)>>1;if(check(mid))ans=mid,r=mid-1;else l=mid+1;}
	if(ans==-1)return 0;ans=ans*b+B-A;if(ans<0)ans=0;
	if(ans%a==0)ans/=a;else ans=ans/a+1;
	ans=ans*a+A;return ans<=C;
}
inline bool c2()
{
	// for(int z=0;z<=C;z++)if(z%a>=A&&z%b>=B)return 1;
	// return 0;
	if(saf())return 1;swap(a,b),swap(A,B);if(saf())return 1;return 0;
}
inline void solve()
{
	cin>>n>>a>>b;if(a>b)swap(a,b);lcm=a*b/__gcd(a,b);ans=(n-1)/a+1+(n-1)/b+1-((n-1)/lcm+1)*2;
	A=(n-1)%a+1,B=(n-1)%b+1,C=(n-1)%lcm;
	if(A==a&&B==b);else if(A==a){if(B<=C)ans--;}else if(B==b){if(A<=C)ans--;}
	else {if(c2())ans-=2;else if(min(A,B)<=C)ans--;}cout<<n-ans<<'\n';
}

bool ED;

signed main()
{
	int time_st=clock();
	cerr<<(&ST-&ED)/1024.0/1024<<endl;
	// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("xor.in","r",stdin);
	// freopen("xor.out","w",stdout);
	int T;cin>>T;while(T--)solve();
	cerr<<(clock()-time_st)/1e6<<endl;return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
5 2 3
10 7 2

output:


result: