3

How many $4$-digits number are a multiple of $3$ but not of $11$ and their digits sum is a perfect square?

My solution
Observe that the only acceptable perfect squares are $9$ and $36$ (if the sum of the digits is $25$ then the number is not a multiple of $3$). Furthermore, $9999$ is the only number having a digits sum of $36$, and it's also a multiple of $11$.

Proceed to count all the permutations of all the numbers in the interval $[1000, 10000)$ having a digits sum of $9$. This is the result.


The last step is rather boring and time-consuming. Since another student solved the problem in no time, I was wondering, is there a faster way?

rubik
  • 9,344
  • if $a+b+c+d=9$, how can $a-b+c-d$ be a multiple of 11? – Empy2 Sep 12 '15 at 15:37
  • @Michael I didn't said that explicitly, but that's the reason in the end I'm just counting numbers with digits sum of $9$, as those cannot be multiple of $11$. – rubik Sep 12 '15 at 15:40
  • Sorry, didn't see that :). – MrYouMath Sep 12 '15 at 15:40
  • Please modify the title of your question, as it seems out of sync with what you're actually asking for. – dohmatob Sep 14 '15 at 14:36
  • @dohmatob I don't think so. I added the problem and my reasoning just as context, but what I am looking for is a fast way to count $4$-digits numbers with digits sum of $9$, which is exactly what the title says and what the accepted answer supplies. – rubik Sep 14 '15 at 14:57

3 Answers3

3

Counting the number of 4-digit numbers and sum 9 can be done using stars and bars really fast (this works because $9$ is less than $10$).

There are $9-1=8$ stars (the first number is at least $1$) and $3$ bars. Hence there are $\binom{8+3}{3}=\frac{11\cdot10\cdot9}{3\cdot2}=11\cdot5\cdot3=165$ such numbers.

Now we have to substract the ones that are multiples of $11$. There are none as you have already realized, that is because $(a+c)-(b+d)\neq 0$ as $a+c$ has a different parity as $b+d$ (they add $9$).

I checked with my computer just to make sure it is correct.

Here is the c++ code, it gives $165$.

#include <cstdio>
#include <cstdlib>
int sumd(int x){
  int a=0;
  while(x!=0){
    a+=x%10;
    x/=10;
  }
  return(a);
}
int main(){
  int a,b=0;
  for(a=1000;a<10000;a++){
    if(sumd(a)==9){
      b++;
    }
  }
  printf("%d\n",b);
}
Asinomás
  • 105,651
  • 1
    What just happened? I would like to understand this method... Any links? What exactly are stars and bars? – Gummy bears Sep 12 '15 at 16:04
  • Yes, $165$ is correct. Are you referring to Theorem two in the wiki page? This method is really powerful, thanks! – rubik Sep 12 '15 at 16:07
  • Here is a related problem I answered a while back, although it is slightly harder, but it explains the main ideas. http://math.stackexchange.com/questions/1031408/how-many-integers-between-one-and-100000-have-the-sum-equal-to-fifteen/1031447#1031447 – Asinomás Sep 12 '15 at 16:08
  • @rubik yes, that is the theorem. Essentially there are four distinct slots (the four digits) and we have to distribute the nine "ones" between the four slots, so it is a stars and bars problem. In this case it was very easy because there are less than ten "ones". When the sum of the digits is larger than ten we need much more carefull analysis (because we aren't allowed to place more than nine "ones" in one slot). The link in my previous comment adresses such a case. – Asinomás Sep 12 '15 at 16:10
  • 1
    Many thanks for the explanation, now it's clearer! – rubik Sep 12 '15 at 16:15
1

How many 4-digits number are a multiple of 3 but not of 11 and their digits sum is a perfect square?

If they are multiples of $3$, then their digit sum is one of $3,6,9,12,15,18,21,24,27, 30, 33, 36$.

If their digit sum is a perfect square, then their digit sum is one of $9, 36$. The only four-digit number with a digit sum of $36$ is $9999$, which is a multiple of $11$. So their digit sum must be $9$.

So we need to count the number of four-digit numbers whose digits sum to $9$. We can use the stars and bars method to find that number but we need to be careful. The binomial coefficient $\binom{n+k-1}{k-1}$ will count the number of k-tuples of non negative integers that sum to $n$. Except we want the first number in the 4-tuple to be positive. We can get that number by computing $\binom{(n-1)+k-1}{k-1}$, the number of k-tuples of non negative integers that sum to $n-1$, and then adding $1$ to the first digit. With $n=9$ and $k=4$, that gives us the number

$$\binom{11}{3} = 165$$

Are any of those $165$ numbers multiples of $11$? No. A digit sum of $9$ implies that such a number must be a multiple of $99$. If that number is $abcd_{10}$, then $ab_{10} + cd_{10}=99$. This implies that $a+b+c+d > 9$

Wolfram Alpha generated the list below with the request "positive four digit numbers whose digit sum is 9".

\begin{array}{c} 1008 & 1017 & 1026 & 1035 & 1044 & 1053 & 1062 & 1071 & 1080 \\ 1107 & 1116 & 1125 & 1134 & 1143 & 1152 & 1161 & 1170 \\ 1206 & 1215 & 1224 & 1233 & 1242 & 1251 & 1260 \\ 1305 & 1314 & 1323 & 1332 & 1341 & 1350 \\ 1404 & 1413 & 1422 & 1431 & 1440 \\ 1503 & 1512 & 1521 & 1530 \\ 1602 & 1611 & 1620 \\ 1701 & 1710 \\ 1800 \\ 2007 & 2016 & 2025 & 2034 & 2043 & 2052 & 2061 & 2070 \\ 2106 & 2115 & 2124 & 2133 & 2142 & 2151 & 2160 \\ 2205 & 2214 & 2223 & 2232 & 2241 & 2250 \\ 2304 & 2313 & 2322 & 2331 & 2340 \\ 2403 & 2412 & 2421 & 2430 \\ 2502 & 2511 & 2520 \\ 2601 & 2610 \\ 2700 \\ 3006 & 3015 & 3024 & 3033 & 3042 & 3051 & 3060 \\ 3105 & 3114 & 3123 & 3132 & 3141 & 3150 \\ 3204 & 3213 & 3222 & 3231 & 3240 \\ 3303 & 3312 & 3321 & 3330 \\ 3402 & 3411 & 3420 \\ 3501 & 3510 \\ 3600 \\ 4005 & 4014 & 4023 & 4032 & 4041 & 4050 \\ 4104 & 4113 & 4122 & 4131 & 4140 \\ 4203 & 4212 & 4221 & 4230 \\ 4302 & 4311 & 4320 \\ 4401 & 4410 \\ 4500 \\ 5004 & 5013 & 5022 & 5031 & 5040 \\ 5103 & 5112 & 5121 & 5130 \\ 5202 & 5211 & 5220 \\ 5301 & 5310 \\ 5400 \\ 6003 & 6012 & 6021 & 6030 \\ 6102 & 6111 & 6120 \\ 6201 & 6210 \\ 6300 \\ 7002 & 7011 & 7020 \\ 7101 & 7110 \\ 7200 \\ 8001 & 8010 \\ 8100 \\ 9000 \end{array}

ALSO

We can also consider counting all of the possible "patterns" of the form $[abcd]$, with $a \le b \le c \le d$, which we define to mean all of the possible four-digit numbers that can be formed using the digits $a,b,c,d$ such that the first digit is not a $0$. For example, the pattern $[0225]$ corresponds to the nine numbers $2025, 2052, 2205, 2250, 2502, 2520, 5022, 5202, 5220$.

\begin{array}{cccc|ccc} \text{pattern} &&&& \text{count} & \dfrac{\#}{\text{count}} &\# \\ \hline 0009 & & & & 1 & 1 & 1 \\ 0018 & 0027 & 0036 & 0045 & 4 & 6 & 24 \\ 0117 & 0144 & 0225 & & 3 & 9 & 27 \\ 0126 & 0125 & 0234 & & 3 & 18 & 54 \\ 0333 & & & & 1 & 3 & 3 \\ 1116 & 2223 & & & 2 & 4 & 8 \\ 1125 & 1134 & 1224 & 1233 & 4 & 12 & 48 \\ \hline & & & & & \text{TOTAL} & 165 \end{array}

0

Answer: 165

Method: Brute-force (7 lines of Python...)

from math import sqrt, floor
is_ps = lambda x: floor(sqrt(x)) ** 2 == x
count = 0
for n in range(1002, 10000, 3):
    if n % 11 and is_ps(sum(map(int, str(n)))):
        count += 1
        print "#%i: %s" % (count, n)
dohmatob
  • 9,535