8.18早上
This commit is contained in:
parent
7e74c42a6e
commit
47380575a5
15
8.16/L-HarmonicNumber(II)/Readme.md
Normal file
15
8.16/L-HarmonicNumber(II)/Readme.md
Normal 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
|
||||||
|
### 工具箱
|
||||||
|
*
|
31
8.16/L-HarmonicNumber(II)/main.cpp
Normal file
31
8.16/L-HarmonicNumber(II)/main.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user