Less than a million and divisible by three

Let us call n N n \in \mathbb{N} good if all the digits of n n are odd and n n is divisible by 3 3 . How many good n < 1 0 6 n<10^6 exist?

Details and Assumptions :

  • Here, we talk about n n in its base 10 10 representation.

  • N \mathbb{N} is the set of natural numbers.


The answer is 6510.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

Emmanuel Lasker
Dec 21, 2014

Let P k ( x ) P_k(x) be P k ( x ) = ( x + x 3 + x 5 + x 7 + x 9 ) k P_k(x)=(x+x^3+x^5+x^7+x^9)^k Imagine that you have expanded P k ( x ) P_k(x) . P k ( x ) = a 9 k x 9 k + . . . + a 1 x + a 0 P_k(x)=a_{9k}x^{9k}+...+a_1x+a_0 The answer of this problem in the case that numbers have k k digits is the sum a 0 + a 3 + . . . + a 9 k a_0+a_3+...+a_{9k} , which is, by the "root of unity filter" theorem, P k ( 1 ) + P k ( ω ) + P k ( ω 2 ) 3 \frac{P_k(1)+P_k(\omega)+P_k(\omega^2)}{3} Where 1 , ω , ω 2 1,\omega,\omega^2 are the three complex cubic roots of unity. Summing up from 1 1 to 6 6 gives k = 1 6 P k ( 1 ) + P k ( ω ) + P k ( ω 2 ) 3 \sum_{k=1}^6\frac{P_k(1)+P_k(\omega)+P_k(\omega^2)}{3} recalling that 1 + ω + ω 2 = 0 1+\omega+\omega^2=0 and that ω k = ω k ( m o d 3 ) \omega^k=\omega^{k \pmod 3} , we can easily find all these values:
5 6 2 3 + 5 5 + 1 3 + 5 4 1 3 + 5 3 2 3 + 5 2 1 3 + 5 + 1 3 = 6510 \frac{5^6-2}{3}+\frac{5^5+1}{3}+\frac{5^4-1}{3}+\frac{5^3-2}{3}+\frac{5^2-1}{3}+\frac{5+1}{3}=\boxed{6510}

Great approach with generating functions.
You can improve your solution by explaining how you reached the final list (IE that each term corresponds to a value of k k ).

Calvin Lin Staff - 6 years, 5 months ago

Log in to reply

After using 1 + ω + ω 2 = 0 1+\omega+\omega^2=0 to simplify P k ( ω ) P_k(\omega) and P k ( ω 2 ) P_k(\omega^2) , they are just geometric progressions.

Pratik Shastri - 6 years, 5 months ago

Should that say " 5 6 + 2 5^6 + 2 "?

Peter Byers - 4 years, 7 months ago
Abhishek Sinha
Dec 21, 2014

Let P ( n , k ) P(n,k) denote the number of integers with n n digits comprising of all odd numerals such that it leaves remainder k k when divided by 3 3 , where 0 k 2 0\leq k \leq 2 .

We have the following recursions P ( n , 0 ) = 2 P ( n 1 , 0 ) + P ( n 1 , 1 ) + 2 P ( n 1 , 2 ) P ( n , 1 ) = 2 P ( n 1 , 0 ) + 2 P ( n 1 , 1 ) + P ( n 1 , 2 ) P ( n , 2 ) = P ( n 1 , 0 ) + 2 P ( n 1 , 1 ) + 2 P ( n 1 , 2 ) P(n,0)=2P(n-1,0)+P(n-1,1)+2P(n-1,2)\\ P(n,1)=2P(n-1,0)+ 2P(n-1,1)+ P(n-1,2)\\ P(n,2)=P(n-1,0)+2P(n-1,1)+2P(n-1,2) with the initial conditions P ( 1 , 0 ) = 2 , P ( 1 , 1 ) = 2 , P ( 1 , 2 ) = 1 P(1,0)=2, P(1,1)=2,P(1,2)=1 . Hence the recursion is now fully specified. We require n = 1 6 P ( n , 0 ) = 6510 \sum_{n=1}^{6}P(n,0)=6510

Maggie Miller
Apr 28, 2016

Of the natural numbers less than 1 0 n 10^n , 5 n 5^n have only odd digits (when viewed as n n -digit numbers with leading zeros). Therefore, the answer is 1 3 k = 1 6 5 k = 5 12 ( 5 6 1 ) = 6510 . \displaystyle\frac{1}{3}\sum_{k=1}^65^k=\frac{5}{12}(5^6-1)=\boxed{6510}.

Is this right? the factor 1 3 \frac{1}{3} seems to imply that the numbers with only odd digits (up to a certain length) are evenly distributed m o d ( 3 ) mod(3) which I don't think is the case in general. Somebody correct me if I'm wrong please!

oscar donlan - 4 years, 9 months ago
Masbahul Islam
Aug 22, 2016

>> a=[x for x in range(1,1000000) if len([i for i in str(x) if int(i)%2!=0])==len(str(x)) and x%3==0]

>> len(a)

6510

Bill Bell
Apr 27, 2015

product is an iterator that makes Cartesian products. In this case then, it behaves like an odometer, creating lists of digits from only the odd digits. The reduce / lambda construction turns the lists of digits from product into numbers to find out if they are divisible by three.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...