Problem Description
给出两个正整数m、n,输出m/n的精确值。
如果m/n是整数或有限小数,那么直接输出它的值。
如果m/n是无限小数,那么输出小数点后到第一个最小循环节为止,并用”()”把最小循环节括起来。
比如,4/2=2,输出”2”;1/5=0.2,输出”0.2”;5/6=0.833333…,输出”0.8(3)”。
Input
输入第一行为一个正整数T,表示有T组测试数据。
接下去T行,每行为一组数据。每行两个个正整数m、n,含义如上。
1<=m<=6,1<=n<=8。
Output
每个样例一行,输出答案。
Sample Input
3
4 2
1 5
5 6
Sample Output
2
0.2
0.8(3)
解题思路
总共n*m=48种情况,直接打表!
参考代码
#include <stdio.h>
const char* p[8][6] = {
"1","2","3","4","5","6",
"0.5","1","1.5","2","2.5","3",
"0.(3)","0.(6)","1","1.(3)","1.(6)","2",
"0.25","0.5","0.75","1","1.25","1.5",
"0.2","0.4","0.6","0.8","1","1.2",
"0.1(6)","0.(3)","0.5","0.(6)","0.8(3)","1",
"0.(142857)","0.(285714)","0.(428571)","0.(571428)","0.(714285)","0.(857142)",
"0.125","0.25","0.375","0.5","0.625","0.75"
};
int main()
{
int T;
scanf("%d",&T);
while (T--){
int n,m;
scanf("%d %d",&m,&n);
printf("%s\n",p[n-1][m-1]);
}
return 0;
}