D. The Beatles
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently a Golden Circle of Beetlovers was found in Byteland. It is a circle route going through n⋅kn⋅k cities. The cities are numerated from 1to n⋅kn⋅k, the distance between the neighboring cities is exactly 11 km.

Sergey does not like beetles, he loves burgers. Fortunately for him, there are nn fast food restaurants on the circle, they are located in the 1-st, the (k+1)(k+1)-st, the (2k+1)(2k+1)-st, and so on, the ((n−1)k+1)((n−1)k+1)-st cities, i.e. the distance between the neighboring cities with fast food restaurants is kk km.

Sergey began his journey at some city ss and traveled along the circle, making stops at cities each ll km (l>0l>0), until he stopped in ss once again. Sergey then forgot numbers ss and ll, but he remembers that the distance from the city ss to the nearest fast food restaurant was aakm, and the distance from the city he stopped at after traveling the first ll km from ss to the nearest fast food restaurant was bb km. Sergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.

Now Sergey is interested in two integers. The first integer xx is the minimum number of stops (excluding the first) Sergey could have done before returning to ss. The second integer yy is the maximum number of stops (excluding the first) Sergey could have done before returning to ss.

Input

The first line contains two integers nn and kk (1≤n,k≤1000001≤n,k≤100000) — the number of fast food restaurants on the circle and the distance between the neighboring restaurants, respectively.

The second line contains two integers aa and bb (0≤a,b≤k20≤a,b≤k2) — the distances to the nearest fast food restaurants from the initial city and from the city Sergey made the first stop at, respectively.

Output

Print the two integers xx and yy.

Examples
input

Copy

2 3
1 1

output

Copy

1 6

input

Copy

3 2
0 0

output

Copy

1 3

input

Copy

1 10
5 3

output

Copy

5 5

Note

In the first example the restaurants are located in the cities 1 and 4, the initial city ss could be 2, 3, 5, or 6. The next city Sergey stopped at could also be at cities 2,3,5,62,3,5,6. Let's loop through all possible combinations of these cities. If both ss and the city of the first stop are at the city 2 (for example, l=6l=6), then Sergey is at ss after the first stop already, so x=1x=1. In other pairs Sergey needs 1,2,31,2,3, or 66 stops to return to ss, so y=6y=6.

In the second example Sergey was at cities with fast food restaurant both initially and after the first stop, so ll is 2, 4, or 6. Thus x=1x=1, y=3y=3.

In the third example there is only one restaurant, so the possible locations of ss and the first stop are: (6,8)(6,8) and (6,4)(6,4). For the first option l=2l=2, for the second l=8l=8. In both cases Sergey needs x=y=5x=y=5 stops to go to ss.

题意 有一个环状排列的城市,相邻距离为1,编号从1到n*k,共n*k个,一个人从s号城市出发,每次走l长度的距离,现在有标号为1,t*k+1,t*(k+1)+1.....(n-1)k+1的城市存在饭店,由于一些原因,这个人忘记了s和l为多少,只记得距离起点s最近的饭店有a的距离,并且走了l长度后,距离此时最近的饭店有b距离,求这个人从s出发,再回到s所需要绕行整个圈的次数的最大值和最小值。

根据题意容易得到,两个饭店之间相距tk,就有t*k=±a±b+l (t为小于等于n的整数) 又有p*l=0 mod k,那么很明显,次数s=n*k/gcd(n*k,l) ,所以只要暴力一遍所有情况即可,复杂度O(4n)。

这个题目第一个坑点是n*k显然爆int,所以全开long long,第二个坑点是既然是long long 初始化最小值最好初始化到long long的上限,因为不涉及加减,所以初始化9e18也可以,不然你会发现你的最小值的初值不够大...

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;int main()
{ll n,k,a,b;cin>>n>>k>>a>>b;ll t[4]={a+b,a-b,-a+b,-a-b};ll p=n*k;ll mx=-1,mn=1e18;for(int i=0;i<4;i++){ll s=t[i];for(int j=0;j<n;j++,s+=k){mx=max(mx,p/(abs(__gcd(p,s))));mn=min(mn,p/(abs(__gcd(p,s))));}}cout<<mn<<" "<<mx<<endl;return 0;
}

View Code

转载于:https://www.cnblogs.com/youchandaisuki/p/10699588.html

Codeforces Round #549 (Div. 2) D. The Beatles相关推荐

  1. Codeforces Round #549 (Div. 2) 1143D. The Beatles

    D. The Beatles time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

最新文章

  1. 送一台电脑显示器,我每天办公都用它,安利!
  2. 2016总结 wjwdive
  3. Python基础-小程序练习(跳出多层循环,购物车,多级菜单,用户登录)
  4. 莫名的证书错误...ERROR ITMS-90035:Invalid Signature.
  5. zkServer.cmd 闪退
  6. easyuefi无法安装只能在基于_SOLIDWORKS2018安装时VC2015安装失败的解决方法
  7. Linux学习总结(70)——Bash 脚本中常用的内置变量汇总
  8. 一汽奔腾b7o价位_全新奔腾B70正式上市,前脸被吐槽酷似某豪华品牌
  9. HttpServletResponse中sendError与setStatus的区别
  10. linux lefse分析,LEfSe分析,你真的懂了么
  11. python十二生肖_十二生肖入诗,妙趣横生,越读越有味道!
  12. 工业设备无线监控解决方案
  13. electron tray click right click
  14. python火车票自我编写_自己动手写100行Python代码抢火车票!
  15. Deep Graph Contrastive Representation Learning
  16. IDA反汇编/反编译静态分析iOS模拟器程序(六)交叉引用
  17. RFID门禁系统快速识别车辆管理
  18. 【openstack一键安装与部署】
  19. 解决mysql导入数据库编码格式不同问题。
  20. 1.微信公众号开发:申请公众平台测试账号

热门文章

  1. Linux环境-自动化部署JAVA
  2. layout_weight如何计算比例?
  3. libgdx和android界面结合,Android游戏引擎libgdx使用教程11:Skin和UI配置文件
  4. 再见了新阳丽舍,再见了新雅阁301
  5. 阿里矢量图在uniapp中的使用
  6. 以太坊黄皮书(1~6章)
  7. Unity FairyGUI 自适应扩展
  8. 【AI实时变声器,声音甜甜的小姐姐背后竟是抠脚大汉】
  9. 将大程序缩减为小程序,数据决定程序结构
  10. Linux下软件安装:Openblas安装