标签:
题目链接 http://acm.hust.edu.cn/vjudge/problem/19592
解题思路
一般容易想到扩展欧几里得算法。
代码
#include<cstdio> #include<cmath> typedef long long ll; int g; double x, k; int gcd(int a, int b, int &d, ll &m, ll &n) { if(!b) { g = d = a; m = 1; n = 0; } else { gcd(b, a%b, d, n, m); n -= m * (a / b); } } int main() { int n; scanf("%d", &n); while(n--) { ll x1, y1; scanf("%lf%lf", &x, &k); int d = (int)x; gcd((int)floor(x/k), (int)ceil(x/k), d, x1, y1); x1 *= (x / g); y1 *= (x / g); printf("%lld %lld\n", x1, y1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ZengWangli/p/5835788.html