submit:545 solved:85
Submitweb Board
Description
In mathematics, we suppose that f (1) =1, F (i)-f (i-1) =1/i, (2<=i<=n)
Input
Input starts with an integer T (≤10000), denoting the number of test cases.
Each case is starts with a line containing an integer n (2≤n≤10^7).
Output
For each case, print the case number and the value of f (n). The answer should is rounded to decimal places.
Sample Input
3
2
3
4
Sample Output
Case 1:1.5
Case 2:1.8333333333
Case 3:2.0833333333
HINT
Test instructions: There is a sequence of values for each item is the preceding number plus one of its subscript points .... Ask the value of the nth item;
Idea: Because of the value is large, so take the way of dividing the table, every 100 items to hit the table and use this as the basis for the calculation of the value can be;
The following code is attached:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
const int M=1E7+10;
Double a[100010];
void init ()
{
double ans=1.0;
for (int i=2;i<=m;i++)
{
ans+=1/double (i);
if (i%100==0)
A[i/100]=ans;
}
}
int main ()
{
int t,k=0,n;
cin>>t;
Init ();
while (t--)
{
cin>>n;
int l=n/100;
Double ans=a[l];
for (int i=l*100+1;i<=n;i++)
ans+=1/double (i);
printf ("Case%d:%.10lf\n", ++k,ans);
}
return 0;
}