HDU 2669 (扩展欧几里得入门)
来源:互联网 发布:如何将mac照片导入u盘 编辑:程序博客网 时间:2024/06/03 18:49
练习一下数学知识了。。
【题目链接】click here~~
【题目大意】Find the nonnegative integer X and integer Y to satisfy X*a + Y*b = 1. If no such answer print "sorry" instead.
求满足式子的x和y否则输出“sorry”
【解题思路】扩展欧几里得的基础了,
扩展欧几里德算法是用来在已知a, b求解一组x,y,使它们满足 等式: ax+by = gcd(a, b) =d(解一定存在,根据数论中的相关定理)。扩展欧几里德常用在求解模线性方程及方程组中。
译文详解:扩展欧几里得入门篇
代码:
/*HDU 2669 扩展欧几里得算法*/#include <bits/stdc++.h>using namespace std;int x,y,n,m,a,b,d;void gcdexted(int a,int b,int &d,int &x,int &y){ if(!b){ d=a; x=1; y=0; } else{ gcdexted(b,a%b,d,y,x); y-=x*(a/b); }}int main(){ while(scanf("%d%d",&a,&b)!=EOF){ gcdexted(a,b,d,x,y); if(d!=1) puts("sorry"); else{ while(x<0){ x+=b; y-=a; } printf("%d %d\n",x,y); } } return 0;}
0 0
- HDU 2669 (扩展欧几里得入门)
- hdu-2669(扩展欧几里得)
- hdu 2669 扩展欧几里得
- HDU 2669 扩展欧几里得
- hdu-2669 扩展欧几里得
- HDU 2669 扩展欧几里得
- hdu - 2669 - Romantic(扩展欧几里得)
- hdu 2669 扩展欧几里得(裸)
- 【HDU】2669 - Romantic(扩展欧几里得)
- HDU 2669:Romantic(扩展欧几里得)
- 【hdu 2669】Romantic(扩展欧几里得)
- hdu 2669 Romantic (扩展欧几里得)
- HDU 2669 Romantic 扩展欧几里得
- HDU 2669 Romantic(扩展欧几里得)
- HDU 2669 Romantic (扩展欧几里得)
- hdu 2669 Romantic 扩展欧几里得
- HDU 2669 Romantic [扩展欧几里得]
- HDU 2669 Romantic扩展欧几里得
- 北师大15校赛
- 移动应用的黑盒测试(2)
- jvm
- html知识笔记(二)——div、table、a标签
- div居中代码 DIV水平居中显示CSS代码
- HDU 2669 (扩展欧几里得入门)
- int、int.Parse()、Convert.ToInt32()区别 //作者:马超
- 修改AFNetworking源文件可接收text/plain和text/html的方法
- 机器学习--线性回归 综述
- 内核怎么通过主设备号找驱动、次设备号找设备
- 汽车之家数据平台架构
- Aerospike-Architecture系列之混合存储
- 查询Oracle某一张表的生成时间
- 怎么在Ubuntu QML应用中侦测到Swipe手势