Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days [la;ra] are lucky, then there are some unlucky days: [ra+1;la+ta−1], and then there are lucky days again: [la+ta;ra+ta] and so on. In other words, the day is lucky for Alice if it lies in the segment [la+kta;ra+kta] for some non-negative integer k

.

The Bob's lucky day have similar structure, however the parameters of his sequence are different: lb

, rb, tb. So a day is a lucky for Bob if it lies in a segment [lb+ktb;rb+ktb], for some non-negative integer k

.

Alice and Bob want to participate in team competitions together and so they want to find out what is the largest possible number of consecutive days, which are lucky for both Alice and Bob.

Input

The first line contains three integers la

, ra, ta (0≤la≤ra≤ta−1,2≤ta≤109

) and describes Alice's lucky days.

The second line contains three integers lb

, rb, tb (0≤lb≤rb≤tb−1,2≤tb≤109

) and describes Bob's lucky days.

It is guaranteed that both Alice and Bob have some unlucky days.

Output

Print one integer: the maximum number of days in the row that are lucky for both Alice and Bob.

Examples
Input

Copy
  1. 0 2 5
    1 3 5
Output

Copy
  1. 2
Input

Copy
  1. 0 1 3
    2 3 6
Output

Copy
  1. 1
Note

The graphs below correspond to the two sample tests and show the lucky and unlucky days of Alice and Bob as well as the possible solutions for these tests.

题意 : 两个人轮流会有幸运天,给你两个人的幸运天的分布情况,是按周期的,问最终重复的幸运天最多是多少?

思路分析 :

代码示例 :

  1. #define ll long long
  2. ll l1, r1, t1;
  3. ll l2, r2, t2;
  4.  
  5. ll gcd(ll a, ll b){
  6. return b==0?a:gcd(b, a%b);
  7. }
  8.  
  9. void solve() {
  10. if (l1 > l2) {swap(l1, l2); swap(r1, r2); swap(t1, t2);}
  11. ll len1 = r1-l1+1, len2 = r2-l2+1;
  12. ll g = gcd(t1, t2);
  13. ll ans = 0;
  14. ll d = (l2-l1)%g;
  15. ans = max(ans, min(len1-d, len2));
  16. ll yd = g-d;
  17. ans = max(ans, min(len1, len2-yd));
  18. printf("%lld\n", ans);
  19. }
  20.  
  21. int main() {
  22. //freopen("in.txt", "r", stdin);
  23. //freopen("out.txt", "w", stdout);
  24.  
  25. cin >> l1 >> r1 >> t1;
  26. cin >> l2 >> r2 >> t2;
  27.  
  28. solve();
  29. return 0;
  30. }

codeforces 上的找两人的幸运天的更多相关文章

  1. 用python实现了一下:甲乙两人互猜数字(数理逻辑)

    今天在园子里看到博客:超难面试题:甲乙两人互猜数字(数理逻辑).然后琢磨了半天,写了个Python程序实现算法,我得出来的结果是1,6或1,8或35,42的组合, 不知道是否正确,请高人指点? 下面列 ...

  2. linux下实现两人、三人无序对话功能

    序:引子 对话功能实际上就是利用管道见得通信.最原始的是一方发另一方收,不能进项交互,发送方的代码如下: /*============================================ ...

  3. codeforces上某题

    一道codeforces上的题目. 题目大意: 定义有k个不同的字符的字符串为好字符串.现在给出一个字符串,求解对该字符串的每个前缀Si至少是多少个好字符串的连接,若不能由好字符串连接而成则输出-1. ...

  4. 《移山之道》第十一章:两人合作 读书笔记 PB16110698 第六周(~4.15)

     本周在考虑阅读材料时,我翻阅了<移山之道>,正好看到这一章:两人合作,心想:正好,我们正值结对作业的紧要关头,书中两人合作的宝贵经验和教诲应当对我们有很大帮助.于是,我开始一边在ddl苦 ...

  5. 这份github上被14万人点赞的Java教程太强了

    前几天有个小伙伴加我之后问了下面的这个问题.我看到后是一脸懵逼的状态,jcombobox?实话说,我已经完全忘了在Java中还有这么个东西. 在网上一番搜索后,才发现原来它是 swing 中的下拉列表 ...

  6. kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸

    kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸

  7. curl文件上传有两种方式,一种是post_fileds,一种是infile

    curl文件上传有两种方式,一种是POSTFIELDS,一种是INFILE,POSTFIELDS传递@实际地址,INFILE传递文件流句柄! );curl_setopt($ch, CURLOPT_PO ...

  8. 在Activiti官方源码上提交的两个bugfix

    前段时间在Activiti官方源码上提交了两个bugfix,截图为证. 第1个是BPMN model输出的bug:

  9. 17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行。请采用循环控制语句来实现。 (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和。) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1

    17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行.请采用循环控制语句来实现. (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和.) 1 1 1 1 ...

随机推荐

  1. computed计算属性(二)

    一.说明 在computed中,可以定义一些属性,即计算属性. 计算属性本质是方法,只是在使用这些计算属性的时候,把他们的名称直接当作属性来使用,并不会把计算属性当作方法去调用,不需要加小括号()调用 ...

  2. Android 隐藏顶部菜单栏

    Android 隐藏状态栏 在Activity中: getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 在fragmen ...

  3. WCF 服务应用程序

    1. 创建 WCF 服务程序和客户端程序,参考如下: https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/getting-started-tut ...

  4. Oracle和可视化视图工具教程

    Oracle数据库安装教程 作者:黑小子-余 Qq:2931445528 微信:Y2931445528 可以找我,我有Oracle数据库安装包及工具   命令: Sqlplus /nolog Conn ...

  5. RecursiveTask和RecursiveAction的使用总结

    一:什么是Fork/Join框架    Fork/Join框架是Java7提供了的一个用于并行执行任务的框架, 是一个把大任务分割成若干个小任务,最终汇总每个小任务结果后得到大任务结果的框架.我们再通 ...

  6. 【题解】有标号的DAG计数3

    [HZOI 2015] 有标号的DAG计数 III 我们已经知道了\(f_i\)表示不一定需要联通的\(i\)节点的dag方案,考虑合并 参考[题解]P4841 城市规划(指数型母函数+多项式Ln), ...

  7. BuilderPattern(建造者模式)-----Java/.Net

    建造者模式(Builder Pattern)使用多个简单的对象一步一步构建成一个复杂的对象.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式

  8. 使用sqlmap中的tamper脚本绕过waf

    使用sqlmap中tamper脚本绕过waf 脚本名:0x2char.py 作用:用UTF-8全角对应字符替换撇号字符 作用:用等价的CONCAT(CHAR(),...)对应替换每个(MySQL)0x ...

  9. 浅谈 OpenGL 中相关阻塞问题

    昨天我遇到一个问题,问题如下: 我使用了延迟渲染,我的渲染流程是:Pass1 --> CUDA并行计算 -->Pass2 CUDA并行计算中需要使用Pass1渲染生成的两张纹理,然而我在G ...

  10. bat无法识别命令、无法识别运算符、结果不符合预期等问题

    1.无法识别的命令等可能为中文字符编码等问题,破坏了bat文件格式,建议去掉中文,加上引号或者重新创建文件.例如:@echo off%~d0cd /d %~dp0title epoch时间转换(%cd ...