# UVa11526 H(n)

## 分析

\begin{aligned} \sum_{i=[{\sqrt n}]+1}^{n}{[\frac{n}{i}]} &=1\times(n-[\frac{n}{2}])+2\times([\frac{n}{2}]-[\frac{n}{3}])+\ldots+[\sqrt{n}]\times([\frac{n}{\sqrt{n}}]-{[\frac{n}{\sqrt n}+1]}) \\ &=n+[\frac{n}{2}]+[\frac{n}{3}]+\ldots+[\frac{n}{\sqrt n}]-[\sqrt n]\times[\frac{n}{[\sqrt n]+1}] \\ &=\sum_{i=1}^{[\sqrt n]}{[\frac{n}{i}]}-{[\sqrt n]}^2 \end{aligned}

## Code

var    n, _, i: longint;function h: int64; inline;var    k, t: longint;begin    h := 0;    t := trunc(sqrt(n));    k := 1;    while k <=t do    begin        h := h + n div k;        inc(k);    end;    h := h * 2 - t * t;end;begin    assign(input, 'main.in'); reset(input);    assign(output, 'main.out'); rewrite(output);    readln(_);    while _ > 0 do    begin        dec(_);        readln(n);        if n <= 0 then            writeln(0)        else            writeln(h);    end;    close(input);    close(output);end.

## OOPS!

A comment box should be right here...But it was gone due to network issues :-(If you want to leave comments, make sure you have access to disqus.com.