Henan Province Multi-school Lianmong (Fri) Problem B: is the registration question XD

Source: Internet
Author: User

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;
}






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.