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

思路:exgcd 最后X为最小正解

代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if(!b) {
x=;y=;return a;
}
ll ans=exgcd(b,a%b,x,y);
ll temp=x;
x=y;
y=temp-a/b*y;
return ans;
}
int main() {
ios::sync_with_stdio(false);
ll a,b,x,y;
while(cin>>a>>b) {
ll g=exgcd(a,b,x,y);
if(g!=) {
cout<<"sorry"<<endl;
} else {
x=(x%b+b)%b;
y=(-a*x)/b;
cout<<x<<" "<<y<<endl;
}
}
return ;
}

最新文章

  1. MRDS学习四——自动型机器车
  2. U3D 动画帧事件问题
  3. Android代码优化----Application节点的模板写法及UI工具类
  4. sql server中index的REBUILD和REORGANIZE
  5. 往Android SDCard中读写入数据
  6. Apache Shiro 快速入门教程,shiro 基础教程 (这篇文章非常好)
  7. 对List对象按照某个成员变量进行排序
  8. 不忘初心 --- 重读&lt;&lt;The C Programming Language&gt;&gt;
  9. C3P0数据库连接池使用中的问题
  10. 一.windows环境下rabbitMQ的的安装和配置
  11. 引用传递this关键字
  12. 剑指offer 06:旋转数组的最小数字
  13. io模块及其API
  14. 海南医院帆软报表 最终版本SQL
  15. String.split()与StringUtils.split()
  16. Javascript和JQuery函数定义方式
  17. android studio 统一管理版本号配置
  18. 【Tomcat】面向初级 Web 开发人员的 Tomcat
  19. (转载)Sublime Text 3 快捷键大全
  20. Filebeat+Logstash+ElasticSearch+Kibana搭建Apache访问日志解析平台

热门文章

  1. 关于docker使用的几个小问题(二)
  2. 利用wsdl.exe自动将wsdl文档转换为C#代码
  3. 5.volatile的应用
  4. 新手入门Flume搭建部署
  5. html2cavans
  6. JQ图片文件上传之前预览功能
  7. 由Python通过__new__实现单例模式,所想到的__new__和__init__方法的区别
  8. .net core 依赖注入扩展,实现随处控制反转
  9. From missionary to firebrand--Eisle Tu [20160102]
  10. Python之Queue模块