codeforce 7C

C. Line

time limit per test1 second

memory limit per test256 megabytes

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.

Examples

input

2 5 3

output

6 -3

代码如下:
#include <iostream>

using namespace std;
typedef long long ll; ll ex_gcd(ll a, ll b, ll&x, ll&y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int ans = ex_gcd(b,a%b,x,y);
int tmp = x;
x = y;
y = tmp - a/b * y;
return ans;
}
int main()
{
ll x, y;
ll a, b, c;
cin >> a >> b >> c;
c *= -1;
ll gcd = ex_gcd(a,b,x,y);
if(c%gcd)
{
cout << "-1" << endl;
}
else
{
int k = c/gcd;
x *= k;
y *= k;
cout << x << " " << y << endl;
} return 0;
}

扩展欧几里得算法

解题报告:codeforce 7C Line的更多相关文章

  1. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

  2. ACM: Just a Hook 解题报告 -线段树

    E - Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   D ...

  3. Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告

    Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...

  4. C-C Radar Installation 解题报告

    C-C    Radar Installation   解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...

  5. 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)

    官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...

  6. ZOJ_3950_How Many Nines 解题报告及如何对程序进行测试修改

    The 17th Zhejiang University Programming Contest Sponsored by TuSimple Solution: #include <stdio. ...

  7. HDU 4303 Hourai Jeweled 解题报告

    HDU 4303 Hourai Jeweled 解题报告 评测地址: http://acm.hdu.edu.cn/showproblem.php?pid=4303 评测地址: https://xoj. ...

  8. CYJian的水题大赛2 解题报告

    这场比赛是前几天洛谷上 暮雪﹃紛紛dalao的个人公开赛,当时基本上都在水暴力分......也没有好好写正解(可能除了T1) 过了几天颓废的日子之后,本蒟蒻觉得应该卓越一下了qwq,所以就打算写一个解 ...

  9. ACM-ICPC 2017 Asia HongKong 解题报告

    ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...

随机推荐

  1. intellij idea 编码设置(乱码问题)

    一般把编辑器设置为 utf-8 如下设置: file-->setting-->editor-->file encodings-->

  2. Allocation-Free Collections(在堆栈上使用内存)

    假设你有一个方法,通过创建临时的List来收集某些数据,并根据这些数据来统计信息,然后销毁这个临时列表.这个方法被经常调用,导致大量内存分配和释放以及增加的内存碎片.此外,所有这些内存管理都需要时间, ...

  3. java-mybaits-00502-案例-映射分析-一对一、一对多、多对多

    1.一对一查询[类属性即可,association ] 案例:查询所有订单信息,关联查询下单用户信息.   注意:因为一个订单信息只会是一个人下的订单,所以从查询订单信息出发关联查询用户信息为一对一查 ...

  4. http://echarts.baidu.com/demo.html#effectScatter-map

    http://echarts.baidu.com/demo.html#effectScatter-map

  5. Linux kill和kill-9区别

    进程状态转换图 kill和kill -9,两个命令在linux中都有杀死进程的效果,然而两命令的执行过程却大有不同,在程序中如果用错了,可能会造成莫名其妙的现象. 执行kill命令,系统会发送一个SI ...

  6. mysql 系统变量和session变量

    mysql系统变量包括全局变量(global)和会话变量(session),global变量对所有session生效,session变量包括global变量.mysql调优必然会涉及这些系统变量的调整 ...

  7. 测试:safenet提供的CheckKey函数 内存泄漏。具体来说是句柄.

    unsigned char vendor_code[] = "7XSQT4jxlSkDJhwqpxxfLwbuxgrYw93OMy+K5sc5pyfTa7HQo1ikLyg7FDuEpgUK ...

  8. delphi webbrowser 跨域访问

    procedure IterateFrames(const AWB: IWebBrowser2);var Doc: IHTMLDocument2; Container: IOleContainer; ...

  9. web前端基础——初识HTML

    1 HTML概念 HTML(Hypertext Markup Language)即超文本标记语言,是网页的描述语言.它其实是一种描述网页的标准,它通过给需要描述的内容加上标签,浏览器按照HTML语言的 ...

  10. python_threading模块实现多线程详解(转)

    综述 Python这门解释性语言也有专门的线程模型,Python虚拟机使用GIL(Global Interpreter Lock,全局解释器锁)来互斥线程对共享资源的访问,但暂时无法利用多处理器的优势 ...