for (int i = 1;i <= n;i++)
for (int j = 1;j <= n/i;j++) ...
是调和级数级别的复杂度,可以由调和级数近似求和公式得到
(T(n)=nsum_{i=1}^n frac{1}{n}=O(n ln n))
具体过程如下
[egin{eqnarray*}
&& sum_{i=1}^nfrac{1}{i} \
&& =sum_{i=1}^nint_i^{i+1}frac{1}{lfloor x
floor}dx \
&& =int_1^{n+1}frac{1}{x}-frac{1}{x}+frac{1}{lfloor x
floor}dx \
&& =int_1^{n+1}frac{1}{x}dx+int_1^{n+1}frac{1}{lfloor x
floor}-frac{1}{x}dx \
&& approx ln(n+1)+gamma
end{eqnarray*}]
其中 (gamma approx 0.5772156649)