Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is denoted as 0.(123). Use xxx.0 to denote an integer. Typical conversions are:
1/3 = 0.(3) 22/5 = 4.4 1/7 = 0.(142857) 2/2 = 1.0 3/8 = 0.375 45/56 = 0.803(571428)
A single line with two space separated integers, N and D, 1 <= N,D <= 100000.
45 56
The decimal expansion, as detailed above. If the expansion exceeds 76 characters in length, print it on multiple lines with 76 characters per line.
0.803(571428)
此题的思想和高精除数有雷同之处,附赠一小段代码:
while(n!=0){
n*=10;
dp[++tot]=n/mod;
n%=mod;
if(vist[n]==0){
vist[n]=1;
g[n]=tot;
}else{
pos=g[n];
biaoji=1;
break;
}
}
核心思想就是寻找循环节,注意题目的要求
usaco-Section 2.4-Fractions to Decimals
原文:http://www.cnblogs.com/buffms/p/5155625.html