I got a question recently, and I am unable to solve it.

Find all natural numbers $N$, With sum of digits $S(N)$, where $N=2\{S(N)\}^2$

I know that $9|N-S(N)$, and since N is twice a square, it must end in $0,2,8$. But I do not know where to go from here. Can anyone help?

The Official Solution from the Organization

We use the fact that $9|n−S(n)$ for every natural number $n$. Hence $S(n)(2S(n)−1)$ is divisible by $9$. Since $S(n)$ and $2S(n)−1$ are relatively prime, it follows that $9$ divides either $S(n)$ or $2S(n)−1$, but not both. We also observe that the number of digits of $n$ cannot exceed $4$. If $n$ has $k$ digits, then $n≥10k−1$ and $$2S(n)^2≤2\cdot(9k)^2=162k^2$$ If $k≥6$, we see that $$2S(n)^2≤162k^2<5^4k^2<10^{k−1}≤n$$ If $k = 5$, we have $$2S(n)^2≤162\cdot25=4150<10^4≤n$$ Therefore $n ≤ 4$ and $S(n) ≤ 36$. If $9|S(n)$, then $S(n) = 9,18,27,36$. We see that $2S(n)^2$ is respectively equal to $162, 648, 1458, 2592$. Only $162$ and $648$ satisfy $n = 2S(n)^2$. If $9|(2S(n)−1)$, then $2S(n) = 9k+1$. Only $k = 1,3,5,7$ give integer values for $S(n)$. In these cases $2S(n)^2 = 50,392,1058,2048$. Here again $50$ and $392$ give $n = 2S(n)^2$. Thus the only natural numbers wth the property $n = 2S(n)^2$ are $50,162,392,648$.

  • $\begingroup$ For what it's worth, $S(N) \mid N$, so that $9 \mid N$. I am not too sure though if it will narrow down things that much. $\endgroup$ – Jose Arnaldo Bebita-Dris Jun 29 '17 at 14:09
  • 1
    $\begingroup$ @JoseArnaldoBebitaDris Do you mean to say that 9 divides N? Because I can think of places where it wouldn't be true. One N I have found is 50, and it is not divisible by 9. $\endgroup$ – MalayTheDynamo Jun 29 '17 at 14:12
  • $\begingroup$ Yes because $N = 2\cdot{S(N)}^2$, which means that $N/S(N) = 2\cdot{S(N)}$ is an integer. In other words, $S(N)$ divides $N$. $\endgroup$ – Jose Arnaldo Bebita-Dris Jun 29 '17 at 14:13
  • $\begingroup$ If that's the case, I would doubt $9 \mid (N - S(N))$. $\endgroup$ – Jose Arnaldo Bebita-Dris Jun 29 '17 at 14:15
  • $\begingroup$ @JoseArnaldoBebitaDris No, that's true. It's a theorem, I think. $\endgroup$ – MalayTheDynamo Jun 29 '17 at 14:16

We want to find an upper bound for $N$ for which it is possible that $N = 2 S(N)^2$. The upper bound that I use in the following is very rough, but I think still just good enough to be able to do the subsequent calculations by hand with a little persistence. Look to the answer of @OscarLanzi for a much cleverer upper bound.

An upper bound for $S(N)$ is $$S(N) \leq 9\cdot \left(\log_{10}(N)+1\right).$$ We can use this upper bound to see that $$ 2 S(N)^2 - N \leq 2 \cdot \left(9\cdot \left(\log_{10}(N)+1\right) \right)^2 - N.$$ For $N = 10^4$ we see that the right hand side of this inequality is $4050 - 10^4 = -5950 < 0$ and by calculating derivatives we can see fairly easily that this expression will only decrease for $N > 10^4$. This means that if we want to find $N$ such that $N = 2 S(N)^2$ we only have to check numbers up to $10^4$, this is a very rough upper bound.

Note that indeed that $N \equiv S(N) \pmod{9}$ so $N$ must satisfy $$N - 2 N^2 \equiv 0 \pmod{9},$$ we deduce that $N \equiv 0 \pmod{9}$ or $N \equiv 5 \pmod{9}$. We see that $N$ must be twice a square and less than $10^4$, so $2S(N)^2 \leq 10^4$, which means that $S(N) \leq \sqrt{\frac{1}{2}\cdot{10^4}} \cong 70.7$. So $S(N)$ must be a number less than or equal to $70$ that is either $0$ or $5$ modulo $9$. There are only fifteen such positive numbers, the list is $$\left\{5,9,14,18,23,27,32,36,41,45,50,54,59,63,68\right\}.$$ These can all be checked separately, the list of these elements squared twice is $$\left\{\mathbf{50},\mathbf{162},\mathbf{392},\mathbf{648},1058,1458,2048,2592,3362,4050,5000,5832,6962,7938,9248\right\}.$$ Sort of surprisingly the first four all fit. These are the only ones, so the final answer is $$N \in \left\{50, 162, 392, 648\right\}.$$ The amount of checking to be done can be reduced by getting a better upper bound.

  • $\begingroup$ I can understand what you did there, with the upper bound, but am unable to understand how you calculated the upper bound. Could you please elaborate? For example, how did logarithms come into play? $\endgroup$ – MalayTheDynamo Jun 29 '17 at 15:06
  • $\begingroup$ @MalayTheDynamo Suppose that a number $n$ consists of $3$ digits, say for example $n = 354$. Then we see that $100 \leq n \leq 1000$, and if we take the logarithm we see that $2 \leq \log_{10}(n) \leq 3$. Generally we can deduce that $\log_{10}(n) + 1$ is always greater or equal to the amount of digits of $n$. The maximal digitsum $S(n)$ of a number with $k$ digits is $9 k$, namely if all digits are $9$. Combining these we find that an upper bound for $S(n)$ is $$9 \cdot \left(\log_{10}(n) + 1\right).$$ $\endgroup$ – Pjotr5 Jun 29 '17 at 15:14
  • $\begingroup$ Oh, thanks. It was perfect. $\endgroup$ – MalayTheDynamo Jun 29 '17 at 15:15

@Pjotr5 identified the solution but asked for a sharper bound. Here all four-digit candidates are eliminated through a descent process leaving only the numbers in his list up to and including $648$.

First off, five-digit numbers give a digit sum no greater than $45$ whose square, doubled, is less than five digits ($2×45^2=4050$). Contradiction. Ditto for more than five digits.

Four-digit numbers give digit sums no more than $36$ whose square, doubled, is $2592$. So a four-digit solution is at most $2592$. But wait, there's more (or less, if you will). If the first digit of the proposed four-digit solution is no more than $2$ the sum of digits is now no more than $29$ giving a bound of $2×29^2=1682$, and then if the first digit has to be $1$ the sum of digits is at most $28$ giving $N\le 1568$.

The four-digit bound can still be lowered more. The bound of $1568$ derived above means the first two digits are no more than $15$ and can't sum to more than $6$. Then the sum of the four digits is no longer bounded only by $28$ but now bounded by $24$. Twice the square of that is $1152$ so now $N \le 1152$.

You know the drill by now. If $N$ has four digits and is less than or equal to $1152$ then the sum of digits is no more than $20$. Twice the square of that is only $800$, less than four digits, so no four-digit candidates are left!

  • 1
    $\begingroup$ Good one :). Together our answers certainly make it possible to solve this problem on a contest. $\endgroup$ – Pjotr5 Jun 29 '17 at 15:48
  • 1
    $\begingroup$ For getting the actual solution @Pjotr5 beat me to it, and in fact I reference that answer. $\endgroup$ – Oscar Lanzi Jun 30 '17 at 9:55
  • 1
    $\begingroup$ @OscarLanzi Thank you :). I'll edit my answer to reference that your upper bound is much better to make the answer more complete. $\endgroup$ – Pjotr5 Jun 30 '17 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.