8.18早上

This commit is contained in:
ljcjames 2022-08-18 11:51:42 +08:00
parent 7e74c42a6e
commit 47380575a5
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# L - Harmonic Number (II)
* https://vjudge.net/contest/509210#problem/L
### 题意
res = res + n / i;求和1 ≤ n < 2^31
### 做法
左右两部分考虑
sqrt(n)前的直接求
后面的按n/2~1,n/3~n/2……,n/m)求
特判m
### 关键词
### 易错点
* 特判m
### 工具箱
*

View File

@ -0,0 +1,31 @@
#include <iostream>
#include<cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
int main()
{
long long t;
long long t1=0;
long long ans;
long long n;
long long now;
long long m;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
ans=0;
m=sqrt(n);
for(long long i=1;i<=m; i++)
{
now=n/i-n/(i+1);
ans+=(i*now);
ans+=(n/i);
}
if(n/m==m)ans-=m;
printf("Case %lld: %lld\n",++t1,ans);
}
return 0;
}