• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 16,comments - 0,trackbacks - 0

            # include <stdio.h>

            typedef long long int LL;

            /***************************************/
            LL Min(LL x, LL y)
            {
            ??????????????? return x < y ? x : y;
            }
            LL Max(LL x, LL y)
            {
            ??????????????? return x > y ? x : y;
            }
            LL gcd(LL x, LL y)
            {
            ??????????????? if (!y) return x;
            ??????????????? return gcd(y, x%y);
            }
            LL ex_gcd(LL a,LL b,LL &x,LL &y)
            {
            ??????????????? if(b==0)
            ??????????????? {
            ??????????????????????????????? x=1;
            ??????????????????????????????? y=0;
            ??????????????????????????????? return a;
            ??????????????? }
            ??????????????? LL g,t;
            ??????????????? g=ex_gcd(b,a%b,x,y);
            ??????????????? t=x;
            ??????????????? x=y;
            ??????????????? y=t-a/b*y;
            ??????????????? return g;
            }
            LL niyuan(LL b,LL p)
            {
            ??????????????? LL x,y;
            ??????????????? ex_gcd(b,p,x,y);
            ??????????????? return x=(x%p+p)%p;
            }
            /***************************************/
            struct frac
            {
            ??????????????? LL n, d;
            } ;
            LL A, B, C, D;
            LL LLabs(LL x)
            {
            ??????????????? return x>0 ? x:-x;
            }
            void slim(frac &x)
            {
            ??????????????? LL tmp = LLabs(gcd(x.d, x.n));
            ??????????????? x.d /= tmp;
            ??????????????? x.n /= tmp;
            }
            frac dif(frac x, frac y)
            {
            ??????????????? frac z;
            ??????????????? z.d = x.d * y.d;
            ??????????????? z.n = LLabs(x.n*y.d-x.d*y.n);
            ??????????????? slim(z);
            ??????????????? return z;
            }
            int cmp(frac x, frac y)
            {
            ??????????????? return x.n*y.d - x.d*y.n>0 ? 1:0;
            }
            frac cal(frac x, frac y, frac BA)
            {
            ??????????????? return cmp(dif(x, BA), dif(y, BA)) ? y:x;
            }
            void solve(void)
            {
            ??????????????? frac BA;
            ??????????????? BA.n = A, BA.d = B;
            ??????????????? LL n1 = niyuan(B, A);
            ??????????????? if (n1 == 0) n1 = A;
            ??????????????? LL d1 = (B*n1-1) / A;
            ??????????????? LL d2 = niyuan(A, B);
            ??????????????? if (d2 == 0) d2 = B;
            ??????????????? LL n2 = (A*d2-1) / B;
            ??????????????? frac a, b;
            ??????????????? a.n = n1, a.d = d1;
            ??????????????? b.n = n2, b.d = d2;
            ??????????????? slim(a), slim(b);
            ??????????????? frac ans = cal(a, b, BA);
            ??????????????? printf("%lld/%lld\n", ans.n, ans.d);
            }
            /***************************************/
            int main()
            {
            ??????????????? freopen("in.txt", "r", stdin);

            ??????????????? int T;
            ??????????????? scanf("%d", &T);
            ??????????????? while (T--)
            ??????????????? {
            ??????????????????????????????? scanf("%lld/%lld", &A, &B);
            ??????????????????????????????? LL tmp = gcd(A, B);
            ??????????????????????????????? if (tmp != 1)
            ??????????????????????????????? {
            ??????????????????????????????????????????????? printf("%lld/%lld\n", A/tmp, B/tmp);
            ??????????????????????????????? }
            ??????????????????????????????? else solve();
            ??????????????? }

            ??????????????? return 0;
            }

            Bert is a programmer with a real fear of floating point arithmetic. Bert has quite successfully used rational numbers to write his programs but he does not like it when the denominator grows large.

            Your task is to help Bert by writing a program that decreases the denominator of a rational number, whilst introducing the smallest error possible. For a rational number A/B, where B > 2 and 0 < A < B, your program needs to identify a rational number C/D such that:

            1. 0 < C < D < B, and
            2. the error | A/B - C/D| is the minimum over all possible values of C and D, and
            3. D is the smallest such positive integer.

            Input

            The input starts with an integer K ( 1$ \le$K$ \le$1000) that represents the number of cases on a line by itself. Each of the following K lines describes one of the cases and consists of a fraction formatted as two integers, A and B, separated by `/' such that:

            1. B is a 32 bit integer strictly greater than 2, and
            2. 0 < A < B

            Output

            For each case, the output consists of a fraction on a line by itself. The fraction should be formatted as two integers separated by `/'.

            Sample Input

            3
            1/4
            2/3
            13/21
            

            Sample Output

            1/3
            1/2
            8/13
            
            posted on 2012-09-15 17:26 yajunw 閱讀(300) 評論(0)  編輯 收藏 引用
            久久亚洲国产精品一区二区| 亚洲va中文字幕无码久久不卡| 久久久久亚洲AV片无码下载蜜桃| 新狼窝色AV性久久久久久| 久久精品麻豆日日躁夜夜躁| 亚洲一本综合久久| 久久久高清免费视频| 国产成人精品白浆久久69| 国产精品久久久久一区二区三区| 99久久精品这里只有精品| 怡红院日本一道日本久久| 久久国产成人午夜AV影院| 久久中文字幕人妻丝袜| 国产精品久久久天天影视| 久久精品无码一区二区三区日韩| 久久AV无码精品人妻糸列| 亚洲国产精品久久久久久| 久久久久久国产精品美女 | 亚洲午夜久久久久妓女影院 | 亚洲精品无码久久久久AV麻豆| 亚洲中文字幕久久精品无码APP| 国产精品成人久久久久久久| 久久精品亚洲一区二区三区浴池| 久久久久国产| 青青草国产精品久久| 久久天天躁狠狠躁夜夜avapp| 欧美成a人片免费看久久| 91精品国产高清久久久久久国产嫩草| 久久无码国产专区精品| 久久久久亚洲AV无码专区网站 | 久久精品国产亚洲综合色| 久久人人爽人人爽人人片AV不| 色综合合久久天天给综看| 91精品免费久久久久久久久| 午夜精品久久久久久毛片| 狠狠综合久久综合88亚洲| 香蕉久久夜色精品国产尤物| 欧美午夜A∨大片久久 | 久久这里都是精品| 久久综合日本熟妇| 国内精品伊人久久久久妇|