BUPT复试专题—分数加法(2014网研)
2024-09-03 14:15:42
题目描述
求2^-a + 2^-b,其中a和b均为正整数,结果用最简分数表示
输入
第一行为测试数据的组数T (1~400)。请注意,任意两组测试数据之间相互独立的。
每组测试数据一行,包含两个整数a和b (2~20)。
每组测试数据一行,包含两个整数a和b (2~20)。
输出
对于每组测试数据,输出结果。
样例输入
2
2 4
3 2
样例输出
5/16
3/8
来源
#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=;
n.mother=n.son=;
while(x--)
m.mother*=;
while(y--)
n.mother*=;
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>;i--)
{
if(n.mother%i==&&n.son%i==)
{
n.mother/=i;
n.son/=i;
}
}
cout<<n.son<<"/"<<n.mother<<endl;
}
}
return ;
}
最新文章
- assert_option()可以用来对assert()进行一些约束和控制
- Qt5 新特性
- js里面的 InttoStr 和 StrtoInt
- jsp-avaBean
- Object转换为json格式
- CommonJS规范
- Android实现网络多线程文件下载
- phpexcel来做表格导出(多个工作sheet)
- Android 自定义对话框(Dialog)位置,大小
- 动画——animation部分
- 如何计算Java对象所占内存的大小
- C语言中getch()、getche()和getchar()
- ios开发之--valueForKeyPath的用法
- Linux基础笔记—— 走进Linux
- 设置获取cookie,setCookie,getCookie
- 【BZOJ3489】A simple rmq problem(KD-Tree)
- Cmake编译SDL2
- Jackson Gson Json.simple part 2
- SpringMVC 文件上传 MultipartFile
- 42 Can stress be Avoided ? 压力能够回避吗 ?