题意:
给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;
}