Calculate 1+1/2+1/3+++1/n
Hangover
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 104558 |
|
Accepted: 50926 |
Description
How far can I make a stack of cards overhang a table? If you had one card, you can create a maximum overhang of half a card length. (We ' re assuming that the cards must is perpendicular to the table.) With both cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the TA Ble by a third of a card length, for a total maximum overhang of a + 1/3 = 5/6 card lengths. In general you can make n cards overhang by + 1/3 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by, the second overhangs Tha third by 1/3, the third overhangs the fourth by the quarter, etc, and the bottom card overhangs the table by 1/(n + 1). This was illustrated in the below.
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the Put. Each test case was a single line containing a positive floating-point number C whose value was at least 0.01 and at the most 5.2 0; C'll contain exactly three digits.
Output
For each test case, the output the minimum number of cards necessary to achieve a overhang of at least C card lengths. Use the exact output format shown in the examples.
Sample Input
1.003.710.045.190.00
Sample Output
3 Card (s) 1 card (s) 273 card (s)
Source
Mid-Central USA 2001
#include <stdio.h>int main () {double S,sum;int i,t;while (scanf ("%lf", &s), s) {for (i=2,sum=0;; i++) {sum+=1.0/i;if (sum>=s) {t=i;break;}} printf ("%d card (s) \ n", t-1);} return 0;}
POJ 1003 hangover&&nyoj 156 Hangover "Math Problem"