<p>The Polymath project sketches an algorithm for computing this function in time O(n^(1/3 + o(1))), see section 2.1 on pages 8-9 of:</p>

<p><a href="http://arxiv.org/abs/1009.3956">http://arxiv.org/abs/1009.3956</a></p>

<p>The algorithm involves slicing the region into sufficiently thin intervals and <em>estimating</em> the value on each, where the intervals are chosen to be thin enough that the estimate will be exact when rounded to the nearest integer. So you compute up to some range directly (they suggest 100n^(1/3) but you could modify this with some care) and then do the rest in these thin slices.</p>

<p>See <a href="https://oeis.org/A006218">the OEIS entry</a> for more information on this sequence.</p>

<p>Edit: I now see that Kerrek SB mentions this algorithm in the comments. In fairness, though, I added the comment to the OEIS 5 years ago so I don't feel bad for posting 'his' answer. :)</p>

<p>I should also mention that no O(1) algorithm is possible, since the answer is around n log n and hence even <em>writing it out</em> takes time > log n.</p>
How to sum sequence?
<p>How can I sum the following sequence:</p>

<pre><code>⌊n/1⌋ + ⌊n/2⌋ + ⌊n/3⌋ + ... + ⌊n/n⌋
</code></pre>

<p>This is simply O(n) solution on C++:</p>

<pre><code>#include &lt;iostream&gt;
int main()
{
   int n;
   std::cin&gt;&gt;n;
   unsigned long long res=0;
   for (int i=1;i&lt;=n;i++)
   {
      res+= n/i;
   }
   std::cout&lt;&lt;res&lt;&lt;std::endl;
   return 0;
}
</code></pre>

<p>Do you know any better solution than this? I mean O(1) or O(log(n)). Thank you for your time :) and solutions</p>

<p>Edit:
Thank you for all your answers. If someone wants the solution O(sqrt(n)):
Python:</p>

<pre class="lang-py prettyprint-override"><code>import math
def seq_sum(n):
 sqrtn = int(math.sqrt(n))
 return sum(n // k for k in range(1, sqrtn + 1)) * 2 - sqrtn ** 2
n = int(input())
print(seq_sum(n))
</code></pre>

<p>C++:</p>

<pre class="lang-c prettyprint-override"><code>#include &lt;iostream&gt;
#include &lt;cmath&gt;
int main()
{
   int n;
   std::cin&gt;&gt;n;
   int sqrtn = (int)(std::sqrt(n));
   long long res2 = 0;
   for (int i=1;i&lt;=sqrtn;i++)
   {
      res2 +=2*(n/i);
   }
   res2 -= sqrtn*sqrtn;
   std::cout&lt;&lt;res2&lt;&lt;std::endl;
   return 0;
}
</code></pre>