-1

We have a function $$ f(n,i)=floor \left(\frac{n}{i} \right)\qquad \text{ for } n,i>0$$

Given any n such that $ 10^{11}< n<10^{12}$, provide a methodology to calculate; $$ \sum_{i=1}^{\infty} f(n,i) $$ Solution should involve less than $ 10^7 $operations

You can use any code or excel for the same

Matti P.
  • 6,262
GAURAV
  • 1
  • 1
    Welcome to MSE. Your question is phrased as an isolated problem, without any further information or context. This does not match many users' quality standards, so it may attract downvotes, or be put on hold. To prevent that, please [edit] the question. This will help you recognise and resolve the issues. Concretely: please provide context, and include your work and thoughts on the problem. These changes can help in formulating more appropriate answers. – José Carlos Santos Oct 16 '19 at 07:28
  • Not exactly the same question, but maybe this will help: https://math.stackexchange.com/questions/740442/how-do-i-evaluate-this-suminvolving-the-floor-function – Matti P. Oct 16 '19 at 10:22

2 Answers2

0

let $$F(n) = \sum_{i=1}^{\infty} f(n,i)$$ Notice that $$f(n,i) = \lfloor\frac{n}{i}\rfloor = Card\{j | j\cdot i\leq n\} $$ So $$F(n) = \sum_{i=1}^{\infty} Card\{j | j\cdot i\leq n\} = Card\{(i,j) | j\cdot i\leq n\}$$ The trick is to split this set in two not disjoint parts : $$\{(i,j) | j\cdot i\leq n\} = \{(i,j) | j\leq \lfloor\sqrt n\rfloor,j\cdot i\leq n\} \cup \{(i,j) | i\leq \lfloor\sqrt n\rfloor,j\cdot i\leq n\} $$ Name these sets : $$ S = A \cup B$$ So $$F(n) = Card(S) = Card(A\cup B) = Card(A)+Card(B)-Card(A\cap B)$$ A and B are symetrical, so their cardinality is the same, and $Card(A\cap B) = \lfloor\sqrt n\rfloor^2$, So $$F(n) = 2\sum_{i=1}^{\lfloor\sqrt n\rfloor} \lfloor\frac{n}{i}\rfloor - \lfloor\sqrt n\rfloor^2 $$

Damien
  • 294
0

Hint:

Assuming $i$ a continuous variable for a second, note that the slope of $\dfrac ni$ is $-\dfrac n{i^2}$ and its absolute value drops below $1$ when $i\approx\sqrt n$. This means that from $1$ to $\sqrt n$ the ratio $\dfrac ni$ changes by several units every time, and then stays constant longer and longer.

So for $n$ like $10^{12}$, you will compute a sum of $10^6$ varying terms, followed by a sum of roughly $10^6$ constant "runs" of increasing length, for a total of $2\cdot10^6$ operations.