/*
CF787A - The Monster
http://codeforces.com/contest/787/problem/A
数学 扩展欧几里得
注意x或y为0的时候要特判
并且结果要大于b和d
*/
#include <cstdio>
int ex_gcd(int a,int b,int &x,int &y)//solve x,y in a*x+b*y=ex_gcd(a,b,x,y)=gcd(a,b);
{
if(b==)
{
x=;
y=;
return a;
}
int ans=ex_gcd(b,a%b,x,y);
int tmp=x;
x=y;
y=tmp-a/b*y;
return ans;
//x = x0 + (b/gcd)*t
//y = y0 – (a/gcd)*t }
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int l=d-b;
int x,y;
if((b-d)%c== && (b-d)/c>= )//特判x==0时
{
printf("%d\n",b);
return ;
}
if((d-b)%a== && (d-b)/a>= )//特判y==0时
{
printf("%d\n",d);
return ;
}
int gcd=ex_gcd(a,c,x,y);
if(l%gcd)
{
printf("-1\n");
return ;
}
x*=l/gcd;
c/=gcd;
if(c<)
c=-c;
x%=c;
while(x<= || b+x*a<d)//结果要大于b和d
x+=c;
printf("%d\n",b+x*a);
return ;
}

CF787A - The Monster的更多相关文章

  1. hdu4950 Monster (水题)

    4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

  2. codeforces 487A A. Fight the Monster(二分)

    题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...

  3. 【BZOJ】【3856】Monster

    又是一道水题…… 重点是分情况讨论: 首先我们很容易想到,如果a*k-b*(k+1)>0的话那么一定能磨死Monster. 但即使不满足这个条件,还有可能打死boss: 1.h-a<1也就 ...

  4. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  5. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  6. Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学

    B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  7. 前端性能优化工具--DOM Monster

    当我们开发web应用的时候,性能是一个永远不能回避的问题.其实对于DOM的性能调试也是一个不可或缺的过程.使用DOM monster你只需要添加到你的”书签中“,在任何需要调试的页面点击这个书签,它就 ...

  8. HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)

    主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...

  9. 3856: Monster

    3856: Monster Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 351  Solved: 161[Submit][Status][Discuss ...

随机推荐

  1. 编程算法 - 数组中的逆序对 代码(C)

    数组中的逆序对 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 在数组中的两个数字假设前面一个数字大于后面的数字, 则这两个数字组成一个逆序对. ...

  2. [Linux]history 显示命令执行的时间

    显示历史命令之行时间 这里的环境是centos5.8 vim  ~/.bashrc 或者 ~/.bash_profile 增加 export HISTTIMEFORMAT="%F %T  & ...

  3. SQLite 常用函数

    SQLite 常用函数 参考: SQLite 常用函数 | 菜鸟教程http://www.runoob.com/sqlite/sqlite-functions.html SQLite 常用函数 SQL ...

  4. B1260 [CQOI2007]涂色paint 区间dp

    这个题和我一开始想的区别不是很大,但是要我独自做出来还是有一些难度. 每一次涂色 只有这两种可能: 1) 把一段未被 覆盖过的区间 涂成 * 色 2) 把一段被一种颜色覆盖的区间涂成 * 色 (并且 ...

  5. 表格td内容过多时,td显示省略号,鼠标移入显示全部内容。

    转自:https://blog.csdn.net/weixin_42193908/article/details/80405014 两种方式显示: 1.title方式显示: <!DOCTYPE ...

  6. Python基础:lambda 匿名函数

    格式 lambda argument1, argument2,... argumentN : expression square = lambda x: x**2 print(square(2)) 与 ...

  7. 在ubuntu中安装Markdown神器Typora

    title: 在ubuntu中安装Markdown神器Typora toc: false date: 2018-09-01 17:48:15 categories: methods tags: ubu ...

  8. Python的filter与map内置函数

    简单的记录下这两个函数的功能: list(filter(lambda x : x % 2, range(10))) 上例是返回了0-10之间的所有基数组成的列表.filter()有2个参数,第一个参数 ...

  9. BZOJ 2729 高精度+组合数学

    思路: 考虑 把男生排成一排 女生和老师往里插 分成两种情况. 1. 女生中间夹着老师 2. 女生中间没有夹着老师 求一下组合* 阶乘就好了 先放Python代码 简洁易懂 def fact(n): ...

  10. 给<hr/>添加样式

    点线式 破折线式 直线式 双线式 脊线式 槽线式 内嵌效果的 突起效果的 border-top:10px 设置水平线的大小 <hr style=" border-top:5px dot ...