1. LightOJ 1234 tabulation (the data size is too large, which is reduced by 100 times), lightoj1234

Source: Internet
Author: User

1. LightOJ 1234 tabulation (the data size is too large, which is reduced by 100 times), lightoj1234

Original question link http://acm.hust.edu.cn/vjudge/contest/121397#problem/A

Meaning: t group data. For each group of data, calculate the sum of 1 + 1/2 + 1/3 + 1/4... + 1/n.

Method: Do not store one of the 100 tables. If the number is less than 100, run it.

# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
# Include <stack>
# Include <queue>
# Include <math. h>
# Include <vector>
Using namespace std;
# Define N 1001010
# Define ll long
# Define INF 0x3f3f3f
# Define met (a, B) memset (a, B, sizeof ());
Vector <int> Q;
Double sum [N];
Void init ()
{
Sum [0] = 0;
Sum [1] = 1.0;
Double ans = 1.0;
For (int I = 2; I <= 100000009; I ++)
{
Ans + = 1.0/(I * 1.0 );
If (I % 100 = 0)
Sum [I/100] = ans;

}
}
Int main ()
{
Init ();
Int t, l, con = 1;
Scanf ("% d", & t );
While (t --)
{
Ll n;
Scanf ("% lld", & n );
L = n/100;
Double ans = sum [l];
For (int I = l * 100 + 1; I <= n; I ++)
Ans + = 1.0/(I * 1.0 );
Printf ("Case % d: %. 10f \ n", con ++, 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.