uva10673 - Play with Floor and Ceil(floor和ceil)

这个算是水题吧,就是对扩展欧几里德算法的应用题目,

题意不难,谈不上思路。

代码如下:

#include <cstdio>
void gcd(int a, int b, int &g, int &x, int &y)
{
    if(b==0) {g = a; x = 1; y = 0;}
    else {gcd(b,a%b,g,y,x); y-=x*(a/b);}
}
int main ()
{
    int cas, x, k, a, b, _x, _y, g;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d%d",&x,&k);
        b = a = x/k;
        if(x%k) b++;
        gcd(a,b,g,_x,_y);
        int c = x/g;//printf("%d %d %d\n",a,b,g);
        printf("%d %d\n",_x*c,_y*c);
    }
    return 0;
}


你可能感兴趣的:(uva10673 - Play with Floor and Ceil(floor和ceil))