Description

The Sky is Sprite. 
The Birds is Fly in the Sky. 
The Wind is Wonderful. 
Blew Throw the Trees 
Trees are Shaking, Leaves are Falling. 
Lovers Walk passing, and so are You. 
................................Write in English class by yifenfei

Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem! 
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisfy X*a + Y*b = 1. If no such answer print "sorry" instead. 

 

Input

The input contains multiple test cases. 
Each case two nonnegative integer a,b (0<a, b<=2^31) 
 

Output

output nonnegative integer X and integer Y, if there are more answers than the X smaller one will be choosed. If no answer put "sorry" instead. 
 

Sample Input

77 51
10 44
34 79
 

Sample Output

2 -3
sorry
7 -3
 
给出 a1 a2
求 x1 x2 使得 a1*x1+a2*x2=1
如果不存在,输出sorry
套用扩展欧里几得算法的模版
注意输出不需要考虑最后的空格控制
注意x1要大于0
 
#include"iostream"
using namespace std; void gcd(int a,int b,int &d,int &x,int &y)
{
if(!b) {d=a;x=;y=;}
else {gcd(b,a%b,d,y,x);y-=x*(a/b);}
} int main()
{
int m,n;
while(cin>>m>>n)
{
int x,y,d;
gcd(m,n,d,x,y);
if(d!=) cout<<"sorry"<<endl;
else
{
while(x<)
{
x+=n;
y-=m;
}
cout<<x<<" "<<y<<endl;
}
}
return ;
}
 
 
 

集训第六周 数学概念与方法 数论 线性方程 I题的更多相关文章

  1. 集训第六周 数学概念与方法 数论 筛素数 H题

    Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“ ...

  2. 集训第六周 数学概念与方法 计数 排列 L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...

  3. 集训第六周 数学概念与方法 概率 F题

    Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...

  4. 集训第六周 数学概念与方法 J题 数论,质因数分解

    Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...

  5. 集训第六周 数学概念与方法 概率 N题

    N - 概率 Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status ...

  6. 集训第六周 数学概念与方法 概率 数论 最大公约数 G题

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  7. 集训第六周 数学概念与方法 UVA 11181 条件概率

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...

  8. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  9. 集训第六周 古典概型 期望 D题 Discovering Gold 期望

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

随机推荐

  1. ios开发-常见的项目文件介绍

    一.项目文件结构示意图 二.文件介绍 1.products文件夹:主要用于mac电脑开发的可执行文件,ios开发用不到这个文件 2.frameworks文件夹主要用来放依赖的框架 3.test文件夹是 ...

  2. java批处理、MySQL批处理

    e: cd MySQL\bin mysql -uroot -proot @pause MySQL批处理.bat e: cd JAVA\jdk1.8.0_77\bin javac Hello.java ...

  3. 12c pdb expdp use DATA_PUMP_DIR meet ORA-39145

    ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: directory name DATA_ ...

  4. Suricata的所有运行方式模式(图文详解)

    不多说,直接上干货! suricata的基本组成.Suricata是由所谓的线程(threads).线程模块 (thread-modules)和队列(queues)组成.Suricata是一个多线程的 ...

  5. window.form增删改查

    效果展示: 查询: 可以查询姓名:民族:姓名+民族:都是空的查询全部 取值取得是姓名: 删除: 修改: 先选中查询之后修改: 添加: 代码部分: 第一张表: 第二张表:主表,民族代码加名称 natio ...

  6. Java数据类型和MySql数据类型对应一览 [转]

    类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述             VARCHAR L+N VARCHAR java.lang.String 12   CHAR N ...

  7. iOS Programming UISplitViewController

    iOS Programming UISplitViewController  The iPad, on the other hand, has plenty of screen space to pr ...

  8. 解决jquery与其他库的冲突

    1.jquery在其他库之后导入 第一种: jQuery.noConflict();//将变量$的控制权限交给其他类库,即将$的控制权让渡给其他类库 jQuery(function(){ jQuery ...

  9. Android原生方式获取经纬度

    两种定位方式:GPS定位.WiFi定位优劣: 如果项目定位要求较高还是建议使用三方地图库 GPS定位相比Wifi定位更精准且可在无网络情况下使用,但在室内基本暴毙无法使用WiFi定位没有室内外限制也不 ...

  10. cf536d——优先队列的运用

    题目 题目:Lunar New Year and a Wander 题目大意:给定一个n个顶点(编号1~n).m条边的图,求从顶点1出发的字典序最小的路径(途径的边可重复). 思路 使用一个优先队列就 ...