Romantic---hdu2669(扩展欧几里德模板)
2016-03-22 21:08
429 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669
详解:扩展欧几里德
详解:扩展欧几里德
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <map> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) #define INF 0x3f3f3f3f #define N 10010 typedef long long LL; LL ex_gcd(LL a, LL b, LL &x, LL &y)///返回值是a和b的最大公约数; { if(b==0) { x = 1; y = 0; return a; } LL c = ex_gcd(b, a%b, x, y); LL temp = x; ///回溯中的x相当于之前的x所以要保留; x = y; ///对应x1 = y2; y = temp - a/b*y; ///对应y1 = x2 - a/b * y1; return c; } int main() { LL a, b, x, y; while(~scanf("%I64d %I64d", &a, &b)) { LL c = ex_gcd(a, b, x, y); if(c!=1) printf("sorry\n"); else { while(x<=0) { x+=b; y-=a; } printf("%I64d %I64d\n", x, y); } } return 0; }
相关文章推荐
- 按键————————朱老师物联网大课堂
- Spring中自动装配的三种方式
- 扩展欧几里得算法
- leetcode198.[DP]House Robber
- UIButton用法详解
- android中的动画:帧动画、补间动画、属性动画
- 204. Count Primes
- Hadoop2.6.4集群环境搭建全记录
- C语言指针 直接寻址与间接寻址详解
- sso单点登录的PHP实现(Laravel框架)
- Android——Intent(意图)
- Java中对象的内存分配问题
- PAT (Advanced Level) Practise 1068 Find More Coins (30)
- 杭电1963 完全背包
- swing
- IOS开发之录音
- 集合 MySet方法实现增删改查
- java基础---->Zip压缩的使用(转)
- cas之登录认证的配置
- Hama0.7.1 执行