I came across the following argument in my discrete maths textbook:
Since $n=O(n), 2n=O(n)$ etc., we have: $$ S(n)=\sum_{k=1}^nkn=\sum_{k=1}^nO(n)=O(n^2) $$
The accompanying question in the book is: What is wrong with the above argument?
Attempt: Performing the summation for $n=2,3$ gives: $$ \sum_{k=1}^2k(2)\leq\sum_{k=1}^22(2)=2(2^2)=O(2^2) $$ $$ \sum_{k=1}^3k(3)\leq\sum_{k=1}^33(3)=3(3^2)=O(3^2) $$ Thus, it seems like the argument is correct. However, I know that I am not correct.
It is a problem of quantifiers $f(n)=O(n)$ means that there exists a constant $M$ that is independant of n such that for all $n$ large enough $|f(n)| \le Mn$. In your case, the implied constant for each term is $k$, which does depend on $n$ since it ranges between $1$ and $n$. So you cannot get this way an implied constant for the sum that does not depend on $n$.