d421. 00332 - Rational Numbers from Repeating Fractions
標籤 :
通過比率 : 91人/110人 ( 83% ) [非即時]
評分方式:
Strictly

最近更新 : 2015-08-28 14:25

內容

 

Now if we let X be the original number (7/22), we can compute the numerator and denominator of the expression

 

 

For  we obtain the following calculation for the numerator of this fraction:

 

 

The denominator is just 1000 - 10, or 990. It is important to note that the expression in the numerator and the denominator of this expression will always yield integer values, and these represent the numerator and denominator of the rational number. Thus the repeated fraction  is the decimal expansion of the rational number 315/990. Properly reduced, this fraction is (as expected) just 7/22.

 

輸入說明

輸入包含好幾行測試資料

每行的第 1 個數字代表 j

接著一個空白

然後是 0.ddddd…(d 代表一個十進位的數字, 最多有 9 個 d,也就是說 k+j 最大可為 9,注意:j 有可能為0,代表不是循環小數)

j=-1 代表輸入結束

輸出說明

對每一行輸入資料

輸出第幾個 Case

然後輸出其有理數的表示法 p/q(需約分)

見 Sample output

範例輸入 #1
2 0.318
1 0.3
2 0.09
6 0.714285
-1
範例輸出 #1
Case 1: 7/22
Case 2: 1/3
Case 3: 1/11
Case 4: 5/7
測資資訊:
記憶體限制: 512 MB
公開 測資點#0 (100%): 1.0s , <1M
提示 :

 

標籤:
出處:
UVa332 [管理者: morris1028 (碼畜) ]

本題狀況 本題討論 排行

編號 身分 題目 主題 人氣 發表日期
沒有發現任何「解題報告」