hdu2669-Romantic
来源:互联网 发布:淘宝开店的类目 编辑:程序博客网 时间:2024/05/01 06:54
题意: 给定a,b,求出方程ax+by=1的解,x是最小的非负数。
简单的扩展欧几里得。
通解为:x = x0 + b*t
y = y0 – a*t
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;int E_Gcd(int a, int b, int &x, int &y){if (b == 0){x = 1;y = 0;return a;}int ans = E_Gcd(b, a%b, x, y);int tem = x;x = y;y = tem - a / b*y;return ans;}int main(){int a, b;int x, y;while (scanf("%d%d", &a, &b) != EOF){int ans = E_Gcd(a, b, x, y);//ans表示为a,b的最大公约数。//printf("%d\n", ans);if (ans != 1) puts("sorry");//如果a,b不互质则无解。else{while (x < 0){x += b;//求满足的最小非负x y -= a;}printf("%d %d\n", x, y);}}return 0;}
0 0
- hdu2669-Romantic
- hdu2669-Romantic
- HDU2669-Romantic
- HDU2669 Romantic
- hdu2669 Romantic(扩展欧几里得)
- HDU2669:Romantic(扩展欧几里得)
- hdu2669 Romantic(扩展欧几里得入门)
- HDU2669 Romantic 扩展欧几里德 对我来说有陷阱
- HDU2669
- hdu2669
- HDU2669
- Romantic
- Romantic
- Romantic
- Romantic
- hdu2669 逆元裸题
- hdu2669 欧几里得水题
- hdu2669 扩展欧几里得
- 怎么设置电脑锁屏不断网
- Hbase存储格式
- Apache Tomcat开机后台启动
- 连续函数的卷积分的详细形象解释
- OpenCV实践之路——方形图片对角线切割
- hdu2669-Romantic
- 跳转后TabBar消失,返回后TabBar出现
- TextView属性详解
- web前端常用工具网址
- BST-----Validate Binary Search Tree
- Educational Codeforces Round 3 B.The Best Gift (数学)
- AWS 构建个人网站(1)
- Sencha Touch 自定义List的三种实现方案
- thrift在centos6.5下编译环境的安装