题意:给出n,求Σ(1/i)。
题解:打表
每隔50打个表。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<map>
#define ll long long
using namespace std;
const int maxn = 2e6 + 10;
int t, n;
double a[maxn];
int main() {
double ans = 0;
int len = 1;
for (double i = 1; i <= 1e8; i += 50) {
for (double j = 0; j < 50; j++) {
ans += 1.0 / (i + j);
}
a[len++] = ans;
}
scanf("%d", &t);
int cas = 0;
while (t--) {
ans = 0;
scanf("%d", &n);
if (n % 50 == 0) {
printf("Case %d: %.8f\n", ++cas, a[n / 50]);
}
else {
ans += a[n / 50];
int x = n / 50 * 50;
for (int i = x + 1; i <= n; i++) {
ans += 1.0 / i;
}
printf("Case %d: %.8f\n", ++cas, ans);
}
}
return 0;
}