題目描述
求2-a+2-b武氓,其中a和b均為正整數(shù)倍阐,結(jié)果請用最簡分?jǐn)?shù)表示。
輸入格式
第一行為測試數(shù)據(jù)的組數(shù)T(1<=T<=400)暑诸。請注意蚌讼,任意兩組測試數(shù)據(jù)之間是相互獨(dú)立的。
每組測試數(shù)據(jù)一行个榕,包含兩個(gè)整數(shù)a和b(2<=a,b<=20)篡石。
輸出格式
對于每組測試數(shù)據(jù),在一行內(nèi)輸出結(jié)果西采,分子和分母用“/”隔開凰萨。
輸入樣例
2
2 4
3 2
輸出樣例
5/16
3/8
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
? ? int a,b;
? ? int up,down;
? ? int t;
? ? scanf("%d",&t);
? ? for (int time=0;time<t;time++){
? ? ? ? //input
? ? ? ? scanf("%d%d",&a,&b);
? ? ? ? if (a<b){//大的在前
? ? ? ? ? ? int temp=a;
? ? ? ? ? ? a=b;
? ? ? ? ? ? b=temp;
? ? ? ? }
? ? ? ? //process
? ? ? ? up=pow(2,a-b)+1;
? ? ? ? down=pow(2,a);
? ? ? ? while (up%2==0){
? ? ? ? ? ? up/=2;
? ? ? ? ? ? down/=2;
? ? ? ? }
? ? ? ? //output
? ? ? ? printf("%d/%d\n",up,down);
? ? }
? ? return true;
}