uva 10673(扩展欧几里德)
2014-03-26 23:12
253 查看
题意:
對任何2個整數 x 和 k,存在另2個整數 p 和 q 使得:
View Code
對任何2個整數 x 和 k,存在另2個整數 p 和 q 使得:
/************************************************** * Author : xiaohao Z * Blog : http://www.cnblogs.com/shu-xiaohao/ * Last modified : 2014-03-26 22:53 * Filename : uva_10673.cpp * Description : * ************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <vector> #include <set> #include <map> #define MP(a, b) make_pair(a, b) #define PB(a) push_back(a) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<unsigned int,unsigned int> puu; typedef pair<int, double> pid; typedef pair<ll, int> pli; typedef pair<int, ll> pil; const int INF = 0x3f3f3f3f; const double eps = 1E-6; ll exgcd(ll a, ll b, ll &x, ll &y){ ll t, m; if(!b && !a) return -1; if(!b) x = 1, y = 0; else { m = exgcd(b, a%b, x, y); t = x, x = y, y = t - (a/b)*y; } return m; } int main() { // freopen("in.txt", "r", stdin); int T; cin >> T; while(T--){ double a, b; cin >> a >> b; ll c = (ll)floor(a/b), d = (ll)ceil(a/b); ll x, y; exgcd(c, d, x, y); ll oa = x*(a/__gcd(c, d)), ob = y*(a/__gcd(c, d)); cout << oa << ' ' << ob << endl; } return 0; }
View Code
相关文章推荐
- UVA 10673 Play with Floor and Ceil (扩展欧几里德)
- uva 12169 扩展欧几里德解不定方程
- uva 10673 Play with Floor and Ceil(扩展gcd)
- UVa 10673 Play with Floor and Ceil(扩展欧几里得)
- UVA 10673 扩展欧几里得
- UVa 10673 - Play with Floor and Ceil (扩展欧几里得)
- UVALive - 6428(扩展欧几里德)
- UVALive 6428 A+B // 扩展欧几里德
- Uva 10673-Play with Floor and Ceil(扩展欧几里得)
- uva 10104 Euclid Problem (数论-扩展欧几里德)
- UVA10413 Crazy Savages 扩展欧几里德的应用
- Uva10090 Marbles 扩展欧几里德的应用
- uva 10104 Euclid Problem (数论-扩展欧几里德)
- UVA 10673 - Play with Floor and Ceil (扩展欧几里得求方程的解)
- UVALive 6428 A+B 扩展欧几里德
- UVA 12493 Stars(扩展欧几里德+欧拉函数)
- 数论初步之扩展欧几里德
- uva 10673 - Play with Floor and Ceil
- poj-2115-C Looooops-扩展欧几里德
- 扩展欧几里德 noip 2012 day2 同余方程