BUPT復試專題—分數加法
阿新 • • 發佈:2018-03-25
復試 post Go fine ace namespace ont other end
每組測試數據一行,包含兩個整數a和b (2~20)。
題目描述
求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 namespacestd; 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; }
BUPT復試專題—分數加法