一开始看不懂那数学符号,以为是大括号,尼玛,后来发现是想下取整和向上取整。
思路:用扩展欧几里得解得一个解,注意floor的是否要转换为double,不然会WA。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long LL;
void ex_gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(!b) { d = a; x = 1; y = 0;}
else { ex_gcd(b, a%b, d, y, x); y -= x*(a/b);}
}
void solve()
{
LL a, b, c, k, d, x, y;
scanf("%ld%ld", &c, &k);
a = (LL)floor(c/(k*1.0)), b = (LL)ceil(c/(k*1.0));
ex_gcd(a, b, d, x, y);
x *= (c/d);
y *= (c/d);
printf("%ld %ld\n", x, y);
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
solve();
}
return 0;
}