zoukankan      html  css  js  c++  java
  • 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
    ",x,y)
    #define pf(x) printf("%d
    ",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;
    }
    

      

  • 相关阅读:
    lnmp环境搭建
    ffmpeg基础使用
    mongodb 副本集搭建
    二 利用pandas统计中国百亿富豪的信息
    1 mongodb安装及启动
    2 mongodb设置密码登录和创建库
    一 pandas读取excle数据
    rancher的使用
    redis主从配置
    redis安装和配置
  • 原文地址:https://www.cnblogs.com/033000-/p/12390142.html
Copyright © 2011-2022 走看看