0
$\begingroup$

I would like to define a function $f(n)$. It must be such that it should produce the sum of all elements till the nth term of the series mentioned below: $$2,2,2,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,10.........$$

I don't know what I must call this sequence, but it is something wherein for every three numbers or $3n^{th}$ number will repeat 4 times while the other numbers will repeat thrice.

$4,7,10,13,16,19,22................$ will repeat 4 times

For better representation,this sequence is just as same as: $$(2,2,2),(3,3,3),(4,4,4,4),(5,5,5),(6,6,6),(7,7,7,7),(8,8,8),(9,9,9),(10,10,10,10),(11.........$$

(The brackets do not have a special meaning)

Example:

$f(1) = 2$

$f(4) = 2+2+2+3$

$f(8) = 2+2+2+3+3+3+4+4$

Though it is easy to write an algorithm in Programming languages like Python or C+, I have no idea on how to represent this function mathematically. I am a novice to this, so please feel free to leave your advice and opinions here! Thank you!

$\endgroup$
3
  • 1
    $\begingroup$ There are multiple ways you could do this... especially if you allow if-conditions in the middle of your expression. Consider using %10 to find the ones-digit of $n$, an if-condition (or disguised if-condition) to determine if the ones-digit was zero, multiplication as necessary, and floor functions if you want to have certain values repeat in the calculation. $\endgroup$
    – JMoravitz
    Commented Apr 18 at 17:08
  • 1
    $\begingroup$ Are you asking about partial sums of some sequence? Either way, if you know how to define it programmatically then you know how to define it mathematically. The same definition works, algorithms are completely valid mathematical definitions. $\endgroup$
    – freakish
    Commented Apr 18 at 17:10
  • 2
    $\begingroup$ In the end though, I would personally find it easiest to build this by defining a piecewise defined function, and define each part separately based on the ones-digit of $n$. The overall function will then follow $f(n) = f(n-10)+30$ and so could be written in terms of $n - (n\%10)$ coupled with this piecewise function. $\endgroup$
    – JMoravitz
    Commented Apr 18 at 17:10

1 Answer 1

1
$\begingroup$

As a start, we need a formula for the $k$th term of the given sequence. It turns out that $$ \biggl( 2 + \biggl\lfloor \frac{3k-1}{10} \biggr\rfloor\biggr)_{k=1}^\infty = (2,2,2,3,3,3,4,4,4,4,\dots). $$ so that \begin{align*} f(n) &= \sum_{k=1}^n \biggl( 2 + \biggl\lfloor \frac{3k-1}{10} \biggr\rfloor\biggr). \end{align*} It turns out that $$ f(n) = \frac{3n^2}{20} + \frac{8n}5 + \delta(n) $$ where $\delta$ is a periodic function with period $10$ (that is, it depends only on the last digit of $n$) with values \begin{multline*} \delta(1) = \frac{1}{4},\, \delta(2) = \frac{1}{5},\, \delta(3) = -\frac{3}{20},\, \delta(4) = \frac{1}{5},\, \delta(5) = \frac{1}{4},\\ \delta(6) = 0,\, \delta(7) = \frac{9}{20},\, \delta(8) = \frac{3}{5},\, \delta(9) = \frac{9}{20},\, \delta(10) = 0. \end{multline*}

$\endgroup$
1
  • $\begingroup$ Thank you for your answer. Could you please tell me, how did you arrive at f(n)=(3n^2/20)+(8n/5)+δ(n) from the previous step? $\endgroup$
    – Teflon
    Commented Apr 18 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .