uva 10673 Play with Floor and Ceil(扩展gcd)
2015-01-01 11:35
337 查看
题意:
给x, k 求:
一组p,q。
解析:
裸exgcd。
代码:
给x, k 求:
一组p,q。
解析:
裸exgcd。
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #include <cmath> #include <stack> #include <vector> #include <queue> #include <map> #include <climits> #include <cassert> #define LL long long using namespace std; const int maxn = 1e6; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = 4 * atan(1.0); const double ee = exp(1.0); void exgcd(LL a, LL b, LL& d, LL& x, LL& y) { if (b == 0) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, d, y, x); y -= a / b * x; } } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int ncase; scanf("%d", &ncase); while (ncase--) { LL o, p; scanf("%lld%lld", &o, &p); LL a = floor((double)o / p); LL b = ceil((double)o / p); LL c = o; LL x, y, d; exgcd(a, b, d, x, y); ///LL r = b / d; x = x / d * c; ///x = (x % r + r) % r; //求最小整数解 y = (c - a * x) / b; printf("%lld %lld\n", x, y); } return 0; }
相关文章推荐
- UVa 10673 Play with Floor and Ceil(扩展欧几里得)
- UVA 10673 - Play with Floor and Ceil (扩展欧几里得求方程的解)
- UVA 10673 Play with Floor and Ceil (扩展欧几里德)
- Uva 10673-Play with Floor and Ceil(扩展欧几里得)
- UVa 10673 - Play with Floor and Ceil (扩展欧几里得)
- UVa 10673 Play with Floor and Ceil (数论)
- Uva10673 Play with Floor and Ceil(拓展欧几里得)
- uva 10673 - Play with Floor and Ceil
- UVA 10673 Play with Floor and Ceil
- UVA 10673 Play with Floor and Ceil (扩展欧几里得算法)
- uva 10673 Play with Floor and Ceil
- UVA10673 - Play with Floor and Ceil
- UVa - 10673 - Play with Floor and Ceil
- UVA10673 - Play with Floor and Ceil(数论)
- UVA 10673 Play with Floor and Ceil(拓展欧几里得)
- UVA 10673 Play with Floor and Ceil
- UVa 10673 - Play with Floor and Ceil
- Play with Floor and Ceil - UVa 10673
- uva 10673 Play with Floor and Ceil
- uva 10673 - Play with Floor and Ceil