循环小数
来源:互联网 发布:人工智能技术及应用 编辑:程序博客网 时间:2024/03/29 10:19
循环小数
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 15 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Given a floating point number X, the form is X=0.a1a2...an(b1b2...bm)(1<=n,m<=8). (b1b2...bm) indicates the repetend. For example, 0.5=0.50=0.5(0)=0.5(00)=1/2,0.3(3)=0.333(33)=1/3.
Please change the floating point number X into a fraction A/B(gcd(A,B)=1).
Please change the floating point number X into a fraction A/B(gcd(A,B)=1).
Input
Input may contain several test cases. The first line is a positive integer, T(T<=10) indicating the number of test cases below.
For each test case, the first line contains two integers n,m(1<=n,m<=8).
The following line contains n numbers a1a2...an.
The following line contains m numbers b1b2...bm.
For each test case, the first line contains two integers n,m(1<=n,m<=8).
The following line contains n numbers a1a2...an.
The following line contains m numbers b1b2...bm.
Output
For each case, output the number A and B(0<A,B) on a single line.
Sample Input
22 250004 2333333
Sample Output
1 21 3
Author
//无限循环小数化为分数
参考这里: http://wenku.baidu.com/view/561773c62cc58bd63186bd87.html
#include<cstdio>__int64 solve(__int64 a,__int64 b){ return b==0?a:solve(b,a%b);}int main(){ int t,n,m; __int64 a,b,z,x,y; scanf("%d",&t); while(t--) { scanf("%d%d%I64d%I64d",&n,&m,&a,&b); x=a; y=0; while(m--) { x*=10; y=y*10+9; } x=x+b-a; while(n--) { y*=10; } z=solve(x,y); //printf("%I64d %I64d\n",x,y); printf("%I64d %I64d\n",x/z,y/z); } return 0;}
0 0
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数
- 循环小数问题
- 循环小数问题
- 无限循环小数
- AMQP协议一
- iOS 通讯录编程【总结】
- 归并排序-归并排序
- java使用泛型不使用任何库函数实现栈
- Jquery中的选择器
- 循环小数
- 超全的Labview VISA驱动,所有版本都有,我的是LABVIEW8.2的,4.5版本就有!
- 用树状数组解决区间查询问题
- Extjs Grid翻页后再刷新无法回到第一页
- uva 474 - Heads / Tails Probability(递推)
- 单例模式
- android系统信息(内存、cpu、sd卡、电量、版本)获取
- openvpn(windows服务端+win/Linux客户端)使用总结
- HDU 4961 Boring Sum