Codeforces7C 扩展欧几里得
| Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input
The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.
Output
If the required point exists, output its coordinates, otherwise output -1.
Sample Input
2 5 3
6 -3
Source
题意:给定a,b,c,求ax+by= - c 时的x和y。
题解:扩展欧几里得模板题。
#include <iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
void exgcd(ll a,ll b,ll &x,ll &y)
{
if(b)
{
exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
else
{
x=;
y=;
}
}
int main()
{
ll a,b,c;
while(cin>>a>>b>>c)
{
c=-c;
ll d=gcd(a,b);
if(c%d)
cout<<-<<endl;
else
{
a/=d;b/=d;c/=d;
ll x,y;
exgcd(a,b,x,y);
cout<<x*c<<" "<<y*c<<endl;
}
}
return ;
}
Codeforces7C 扩展欧几里得的更多相关文章
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- UVA 12169 Disgruntled Judge 枚举+扩展欧几里得
题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...
- UVA 10090 Marbles 扩展欧几里得
来源:http://www.cnblogs.com/zxhl/p/5106678.html 大致题意:给你n个球,给你两种盒子.第一种盒子每个盒子c1美元,可以恰好装n1个球:第二种盒子每个盒子c2元 ...
- POJ 1061 青蛙的约会 扩展欧几里得
扩展欧几里得模板套一下就A了,不过要注意刚好整除的时候,代码中有注释 #include <iostream> #include <cstdio> #include <cs ...
- 【64测试20161112】【Catalan数】【数论】【扩展欧几里得】【逆】
Problem: n个人(偶数)排队,排两行,每一行的身高依次递增,且第二行的人的身高大于对应的第一行的人,问有多少种方案.mod 1e9+9 Solution: 这道题由1,2,5,14 应该想到C ...
- poj 2891 扩展欧几里得迭代解同余方程组
Reference: http://www.cnblogs.com/ka200812/archive/2011/09/02/2164404.html 之前说过中国剩余定理传统解法的条件是m[i]两两互 ...
- poj 2142 扩展欧几里得解ax+by=c
原题实际上就是求方程a*x+b*y=d的一个特解,要求这个特解满足|x|+|y|最小 套模式+一点YY就行了 总结一下这类问题的解法: 对于方程ax+by=c 设tm=gcd(a,b) 先用扩展欧几里 ...
- poj 1061 扩展欧几里得解同余方程(求最小非负整数解)
题目可以转化成求关于t的同余方程的最小非负数解: x+m*t≡y+n*t (mod L) 该方程又可以转化成: k*L+(n-m)*t=x-y 利用扩展欧几里得可以解决这个问题: eg:对于方程ax+ ...
- SGU 140 扩展欧几里得
题目大意: 给定序列a[] , p , b 希望找到一个序列 x[] , 使a1*x1 + a2*x2 + ... + an*xn = b (mod p) 这里很容易写成 a1*x1 + a2*x2 ...
随机推荐
- 【BZOJ-3172】单词 AC自动机
3172: [Tjoi2013]单词 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2567 Solved: 1200[Submit][Status ...
- Codeforces 548B Mike and Fun
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- QA要懂的Linux命令
<一>软件安装相关QA经常需要安装测试软件(jmeter.Mock.python环境搭建.java环境搭建),或者配置测试环境(nginx.ci等),需要了解linux下如何安装软件.在工 ...
- Weak is not weak,Strong is not strong
问题 今天做浏览器Controller的时候,碰到了一个奇怪的问题:每次pop浏览器controller之后,等几秒,总会碰到类似下面的错误(其中的xxxController就是浏览器或继承他的子类C ...
- MyEclipse------execute()使用方法
execute()方法应该仅在语句能返回多个ResultSet对象,多个更新计数或ResultSet对象与更新计数的组合时使用. testExecute.jsp <%@ page languag ...
- yum被锁Another app is currently holding the yum lock; waiting for it to exit...
可能是系统自动升级正在运行,yum在锁定状态中. 可以通过强制关掉yum进程: #rm -f /var/run/yum.pid 然后就可以使用yum了.
- 使用servletAPI三种方式简单示例
一.直接实现Action接口或集成ActionSupport类(推荐) public class HelloAction implements Action { @Override public St ...
- eclipse 左边目录结构下五referenced library解决办法
没有referenced library,加入多个jar包,导致项目看上去庞大 解决办法: 在Package Explorer窗口中会出现Referenced Libraries,但Java EE 透 ...
- block中防止循环引用的一个高大上的宏定义
看惯了什么tempSelf weakSelf,来点高大的 #define weakify(...) \ rac_keywordify \ metamacro_foreach_cxt(rac_weaki ...
- spring 标注 详解
http://snowolf.iteye.com/blog/578452 http://snowolf.iteye.com/blog/578452 非常棒的入门读物