B - 楼下水题

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

Input
2 5 3
Output
6 -3
题解:
模版欧几里德;Ax+By=gcd;
找到x,y;分式两边同乘以(-c/gcd)也就是x*(-c/gcd),y*(-c/gcd);就好了;
代码:
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long LL;
using namespace std;
void e_gcd(LL &x,LL &y,LL &d,LL a,LL b){
if(!b){
d=a;
x=;
y=;//y可以为任意数;因为b为0
}
else{
e_gcd(x,y,d,b,a%b);//欧几里德;
LL temp=x;
x=y;
y=temp-a/b*y;
}
}
int main(){
LL a,b,c,x,y,d;
while(~scanf("%lld%lld%lld",&a,&b,&c)){
e_gcd(x,y,d,a,b);
//printf("%d %d %d\n",x,y,d);
if(c%d!=)puts("-1");
else printf("%lld %lld\n",x*(-c/d),y*(-c/d));
}
return ;
}

B - 楼下水题(扩展欧几里德)的更多相关文章

  1. D - 楼下水题(kmp+Manacher)

    D - 楼下水题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Statu ...

  2. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  3. HDU4596 Yet another end of the world 扩展欧几里德性质

    这题坑了,我真该吃翔啊,竟然一開始方程设错了并且没有去想连列的问题,我真是坑货,做不出就该又一次理一下嘛.操蛋. 题意:给了N组x,y,z然后 问你是否存在两个或者两个以上的id,是的 id%x的值在 ...

  4. poj1061 青蛙的约会 扩展欧几里德的应用

    这个题解得改一下,开始接触数论,这道题目一开始是看了别人的思路做的,后来我又继续以这种方法去做题,发现很困难,学长告诉我先看书,把各种词的定义看懂了,再好好学习,我做了几道朴素的欧几里德,尽管是小学生 ...

  5. POJ 1061 青蛙的约会(扩展欧几里德)

    点我看题目 题意 : 中文题不详述. 思路 : 设经过s步后两青蛙相遇,则必满足(x+m*s)-(y+n*s) = K*L(k = 0,1,2....) 变形得:(n-m)*s+K*L = x-y ; ...

  6. HDU 1576 A/B 扩展欧几里德算法

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. POJ 2891 扩展欧几里德

    这个题乍一看跟剩余定理似的,但是它不满足两两互素的条件,所以不能用剩余定理,也是给了一组同余方程,找出一个X满足这些方程,如果找不到的话就输出-1 因为它不满足互素的条件,所以两个两个的合并,最后合成 ...

  8. 扩展欧几里德 POJ 1061

    欧几里德的是来求最大公约数的,扩展欧几里德,基于欧几里德实现了一种扩展,是用来在已知a, b求解一组x,y使得ax+by = Gcd(a, b) =d(解一定存在,根据数论中的相关定理,证明是用裴蜀定 ...

  9. POJ2115 C Looooops 扩展欧几里德

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ2115 题意 对于C的for(i=A ; i!=B ;i +=C)循环语句,问在k位存储系统中循环几次 ...

随机推荐

  1. 提供一段Excel获取Title的标题,类似于A、AA、AAA,我们操作Excel的时候通常根据次标题来获取一定的操作范围。

    /******************************************** FormatExcelColumTitle Purpose Get excel title like &qu ...

  2. 使用VisualStudio发布ASP.NET网站

    1.右击网站点击“发布网站” 2.选择或导入发布配置文件.→新建配置文件. 3.输入名称test.→点击确定. 4.发布方法选择文件系统. 5.选择目标位置.→点击下一步 6.文件发布选项选择三个选项 ...

  3. java——多线程——单例模式的static方法和非static方法是否是线程安全的?

    单例模式的static方法和非static方法是否是线程安全的? 答案是:单例模式的static方法和非static方法是否是线程安全的,与单例模式无关.也就说,如果static方法或者非static ...

  4. MarkDown使用 (三)表格

    MarkDown表格的用法 MarkDown表格的用法 例如: $$ \begin{array}{c|lcr} n & \text{Left} & \text{Center} & ...

  5. mssql索引使用情况查询

    可通过查询dm_db_index_usage_stats表取得对应表索引被使用次数. 列名 数据类型 说明 database_id smallint 在其中定义表或视图的数据库的 ID. object ...

  6. [C++]Saving the Universe——Google Code Jam Qualification Round 2008

    Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...

  7. android-数据持久化

    动态文件 String FILE_NAME = "tempfile.tmp"; try { //读 FileInputStream fis = openFileInput(FILE ...

  8. gallery 从最左边开始显示并且默认选中第一个

    import android.content.Context; import android.graphics.Camera; import android.graphics.Matrix; impo ...

  9. 记userscripts.org

    发现一些Firefox用户脚本不起作用,userscripts.org访问不能有一个很长的一段时间,我还以为出了什么问题没出去检查.前几天有时间检查脚本,在路上,然后返回到userscripts.or ...

  10. HDU1046:Gridland

    Problem Description For years, computer scientists have been trying to find efficient solutions to d ...