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. LMAX Disruptor 原理

    http://mechanitis.blogspot.com/search/label/disruptor http://ifeve.com/disruptor/, 并发框架Disruptor译文 h ...

  2. 如何使用 opencv 加载 darknet yolo 预训练模型?

    如何使用 opencv 加载 darknet yolo 预训练模型? opencv 版本 > 3.4 以上 constexpr const char *image_path = "da ...

  3. LeetCode_Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. PHP & “Data” URL scheme(转)

    基本上所有的对文件操作的API, 都迁移到的了PHP stream上, 所以, 绝大部分对文件操作的API都是支持Data URL的. 当某个API需要操作对象是文件的时候, 我们其实是可以采用Dat ...

  5. Python高级特性(1):Iterators、Generators和itertools(转)

    译文:Python高级特性(1):Iterators.Generators和itertools [译注]:作为一门动态脚本语言,Python 对编程初学者而言很友好,丰富的第三方库能够给使用者带来很大 ...

  6. java实现简单的数据库的增删查改,并布局交互界面

        一.系统简介 1.1.简介  本系统提供了学生信息管理中常见的基本功能,主要包括管理员.管理员的主要功能有对学生信息进行增加.删除.修改.查找等操作,对信息进行管理,对信息进行修改.查找等操作 ...

  7. instanceof判断参数是否是给定的类型

    if(ofj instanceof CLOB) {//判断ofj是否是CLOB类型,如果是则把CLOB内容解析出来,放入TZNR字段中并返回 CLOB ft = (CLOB)ofj; String c ...

  8. Java 运算符及优先级

    运算符 分割符: , ; [] () 算数运算符: + - * / % ++ -- 关系运算符: > < >= <= == != 逻辑运算符: ! & | ^ & ...

  9. ambari关于ranger的一个大坑----端口永远是3306,需要手动修改

    ambari关于ranger的一个大坑----端口永远是3306 这个坑是我在搭建ambari环境的时候发现的,我并没有找到原因,求助同事,然后一步步循着蛛丝马迹和试探,终于解决了,然而也揭露了amb ...

  10. HomeBrew的安装详细步骤

    1)终端输入:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master ...