传统弱校HFUT的蒟蒻,真相只有一个

BUPT复试专题—分数加法(2014网研)

题目描述

求2^-a + 2^-b,其中a和b均为正整数,结果用最简分数表示

输入

第一行为测试数据的组数T (1~400)。请注意,任意两组测试数据之间相互独立的。
每组测试数据一行,包含两个整数a和b (2~20)。
 

输出

对于每组测试数据,输出结果。

样例输入

2
2 4
3 2

样例输出

5/16
3/8

来源

2014网研A题 

#include<algorithm>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
struct donser
{
    ll son;
    ll mother;    
};
int main()
{
    ll a;
    while(~scanf("%d",&a)) 
    {
        while(a--)
        {
            ll x,y;
            cin>>x>>y;
            donser m,n;
            m.mother=m.son=1;
            n.mother=n.son=1;
            while(x--)
                m.mother*=2;
            while(y--)
                n.mother*=2;
            ll temp=m.mother*n.mother;
            m.son=n.mother;
            n.son=m.mother;
            n.son=n.son+m.son;
            n.mother=temp;
            for(ll i=n.son;i>1;i--)
            {
                if(n.mother%i==0&&n.son%i==0)
                {
                    n.mother/=i;
                    n.son/=i;
                }
            }
            cout<<n.son<<"/"<<n.mother<<endl;
        }    
    }
    return 0;
}

 

posted @ 2018-03-25 17:11  未名亚柳  阅读(227)  评论(0编辑  收藏  举报