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

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<cstdio>
#include<algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
const long long M=1e17;
const int N=1e8;
double a[N+5]={0};
const int w=50;
double a[N/w+5];
int t,n;
int t1;
inline void cun()
{
a[0]=0;a[1]=1;
for(int i=2;i<=N;i++)
int cur=1;
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()
@ -27,13 +34,19 @@ inline void cun()
//}
int main()
{
cun();
// ce();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("Case %d: %.8llf\n",++t1,a[n]);
}
cun();
// ce();
scanf("%d",&t);
while(t--)
{
scanf("%d",&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;
}