cf1142A

cf1142A

 

题解:起点位置固定,枚举终点即可

#include<bits/stdc++.h>
#define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
#define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x)  cout<<it<<endl;
#define pii pair<int,int>
#define sc(x) scanf("%d",&x)
using namespace std;
typedef long long ll;
const int maxn=1e4+5;
const int maxm=2e5+5;
const int inf=1e9;
ll n,k,a,b;
int main() {
	cin>>n>>k>>a>>b;
	ll s=a+1,l,mi=1e18,mx=-1e18;
	for(int i=1;i<=n;i++){
		ll lst=(i-1)*k+1-b;
		if(lst<=0) lst+=k*n;
		if(lst>s) l=lst-s;
		else l=lst-s+n*k;
		ll now=n*k/__gcd(l,n*k);
		assert(now>=1);
		mi=min(mi,now);
		mx=max(mx,now);
		ll nex=(i-1)*k+1+b;
		if(nex>n*k) nex-=n*k;
		if(nex>s) l=nex-s;
		else l=nex-s+n*k;
		now=n*k/__gcd(l,n*k);
		assert(now>=1);
		mi=min(mi,now);
		mx=max(mx,now);
	}
	cout<<mi<<' '<<mx<<endl;
}

  

 

上一篇:SQL Server 2008 R2执行存储过程sp_MailItemResultSets引起大量PREEMPTIVE_OS_WAITFORSINGLEOBJEC等待


下一篇:【挑战】How to Get Highest Score in Garupa?