hdu2669扩展欧几里得
2012-07-06 15:01
183 查看
赤裸裸的,直接贴代码。。不过注意题目要求X非负,所以最后还要再处理一下。。
/* * hdu2669/win.cpp * Created on: 2012-7-6 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; int gcd(int m, int n) { int r = m % n; while (r) { m = n; n = r; r = m % n; } return n; } int extend_gcd(int a, int b, int &x, int &y) { int d, xx; if (b == 0) { x = 1, y = 0; return a; } d = extend_gcd(b, a % b, x, y); xx = x; x = y; y = xx - a / b * y; return d; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif int m, n; while(scanf("%d%d", &m, &n) == 2) { if(gcd(m, n) > 1) { puts("sorry"); } else { int x, y; extend_gcd(m, n, x, y); while(x < 0) { x += n; y -= m; } printf("%d %d\n", x, y); } } return 0; }
相关文章推荐
- hdu2669 Romantic(扩展欧几里得入门)
- HDU2669:Romantic(扩展欧几里得)
- hdu2669 Romantic(扩展欧几里得)
- hdu2669 扩展欧几里得
- 扩展欧几里得
- my扩展欧几里得
- UESTC 87 Easy Problem With Numbers(扩展欧几里得+线段树)
- hdu-2669 扩展欧几里得
- POJ1061 青蛙的约会(扩展欧几里得)
- hdoj2669Romantic【扩展欧几里得】
- hdoj1576A/B【扩展欧几里得】
- 扩展欧几里得求逆元
- poj 2142 The Balance(扩展欧几里得)
- Poj 1061:青蛙的约会(扩展欧几里得)
- POJ 2215 扩展欧几里得
- UVA - 12169 - Disgruntled Judge (扩展欧几里得)
- POJ 2115 C Looooops(扩展欧几里得)
- 扩展欧几里得
- Romantic 欧几里得的扩展
- hdoj 1576 A/B [扩展欧几里得.逆元]