C. Line (扩展欧几里得)
1 second
256 megabytes
standard input
standard output
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.
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.
If the required point exists, output its coordinates, otherwise output -1.
2 5 3
6 -3
ax+by+c=0,化为ax+by=-c/gcd(a,b)*gcd(a,b),
套拓展欧几里得就可以解出了
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
typedef long long LL;
LL exgcd(LL a, LL b, LL &x, LL &y) {
if (b == ) {
x = , y = ;
return a;
}
LL g = exgcd(b, a % b, x, y);
LL t;
t = x, x = y, y = t - (a / b) * y;
return g;
}
int main() {
LL a, b, c, x, y;
cin >> a >> b >> c;
LL t = exgcd(a, b, x, y);
if (c % t == ) printf("%lld %lld\n", -x * c / t, -y * c / t);
else printf("-1\n");
return ;
}
C. Line (扩展欧几里得)的更多相关文章
- Line(扩展欧几里得)
题意:本题给出一个直线,推断是否有整数点在这条直线上: 分析:本题最重要的是在给出的直线是不是平行于坐标轴,即A是不是为0或B是不是为0..此外.本题另一点就是C输入之后要取其相反数,才干进行扩展欧几 ...
- Codeforces7C 扩展欧几里得
Line Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- POJ2115(扩展欧几里得)
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23700 Accepted: 6550 Descr ...
- Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7
Root Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- UVA 10090 Marbles(扩展欧几里得)
Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
- Root(hdu5777+扩展欧几里得+原根)
Root Time Limit: 30000/1500 ...
- Gym100812 L 扩展欧几里得
L. Knights without Fear and Reproach time limit per test 2.0 s memory limit per test 256 MB input st ...
- 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- ...
随机推荐
- 域名、IP地址、URL关系
域名是个文字形式记录的IP地址 IP地址是计算机在网络中的门牌号! URL是网页地址 例如1: http://zhidao.baidu.com/question/14674128.html 是URL ...
- lintcode100 删除排序数组中的重复数字
删除排序数组中的重复数字 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成. 您在真实的 ...
- n! 阶乘
其实1.2.3.4.6.7…都是可以不用考虑的,因此选择以5为迭代步数即可. 首先,这些数字都可以不用进行%5(对5取余数)运算,因此每次循环时可以直接将函数的count变量直接加1.其次,考虑25. ...
- jquery取radio单选按钮
// var strMess = '<%=Exchange() %>';// if (strMess == "兑换成功") {// ...
- Ext JS 6学习文档-第6章-高级组件
Ext JS 6学习文档-第6章-高级组件 高级组件 本章涵盖了高级组件,比如 tree 和 data view.它将为读者呈现一个示例项目为 图片浏览器,它使用 tree 和 data view 组 ...
- JQuery中each方法实现
each()函数是基本上所有的框架都提供了的一个工具类函数,通过它,你可以遍历对象.数组的属性值并进行处理. jQuery和jQuery对象都实现了该方法,对于jQuery对象,只是把each方法简单 ...
- iOS AVAudioPlayer播放音频时声音太小
iOS AVAudioPlayer播放音频时声音太小 //引入AVFoundation类库,设置播放模式就可以了 do { try AVAudioSession.sharedInstance().ov ...
- error : Web 项目“RealEstate.Web”的 URL“http://localhost:20000”已配置为将 IIS 用作 Web 服务器,但是当前在 IIS Express W
error : Web 项目"RealEstate.Web"的 URL"http://localhost:20000"已配置为将 IIS 用作 Web 服务器 ...
- PAT L1-039 古风排版
https://pintia.cn/problem-sets/994805046380707840/problems/994805091888906240 中国的古人写文字,是从右向左竖向排版的.本题 ...
- Delphi XE4 TStringHelper用法详解
原文地址:Delphi XE4 TStringHelper用法详解作者:天下为公 Delphi XE4的TStringHelper,对操作字符串进一步带来更多的方法,估计XE5还能继续用到. Syst ...