有一个数据最后一位数字对不上

This commit is contained in:
ljcjames 2022-08-18 09:19:19 +08:00
parent 700050498c
commit 9e1a6289e8
1 changed files with 26 additions and 13 deletions

View File

@ -1,20 +1,27 @@
//有一个数据最后一位数字对不上
#include <iostream> #include <iostream>
#include<cstdio> #include<cstdio>
#include<algorithm> #include<algorithm>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
using namespace std; using namespace std;
const long long M=1e17;
const int N=1e8; const int N=1e8;
double a[N+5]={0}; const int w=50;
double a[N/w+5];
int t,n; int t,n;
int t1; int t1;
inline void cun() inline void cun()
{ {
a[0]=0;a[1]=1; int cur=1;
for(int i=2;i<=N;i++) for(int i=1;i<=N;i++)
{ {
a[i]=a[i-1]+(1.0/i); a[cur]+=(1.0/i);
if(i%w==0)
{
// printf("%llf,",a[cur]);
cur++;
a[cur]=a[cur-1];
}
} }
} }
//void ce() //void ce()
@ -33,7 +40,13 @@ int main()
while(t--) while(t--)
{ {
scanf("%d",&n); scanf("%d",&n);
printf("Case %d: %.8llf\n",++t1,a[n]); int now=n/w;
double ans=a[now];
for(int i=now*w+1;i<=n;i++)
{
ans+=(1.0/i);
}
printf("Case %d: %.10llf\n",++t1,ans);
} }
return 0; return 0;
} }