Let us call n ∈ N good if all the digits of n are odd and n is divisible by 3 . How many good n < 1 0 6 exist?
Details and Assumptions :
Here, we talk about n in its base 1 0 representation.
N is the set of natural numbers.
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.
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
).
Log in to reply
After using 1 + ω + ω 2 = 0 to simplify P k ( ω ) and P k ( ω 2 ) , they are just geometric progressions.
Should that say " 5 6 + 2 "?
Let P ( n , k ) denote the number of integers with n digits comprising of all odd numerals such that it leaves remainder k when divided by 3 , where 0 ≤ k ≤ 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 ) with the initial conditions 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 ) = 6 5 1 0
Of the natural numbers less than 1 0 n , 5 n have only odd digits (when viewed as n -digit numbers with leading zeros). Therefore, the answer is 3 1 k = 1 ∑ 6 5 k = 1 2 5 ( 5 6 − 1 ) = 6 5 1 0 .
Is this right? the factor 3 1 seems to imply that the numbers with only odd digits (up to a certain length) are evenly distributed m o d ( 3 ) which I don't think is the case in general. Somebody correct me if I'm wrong please!
>> 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
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.
Problem Loading...
Note Loading...
Set Loading...
Let P k ( x ) be P k ( x ) = ( x + x 3 + x 5 + x 7 + x 9 ) k Imagine that you have expanded P k ( x ) . P k ( x ) = a 9 k x 9 k + . . . + a 1 x + a 0 The answer of this problem in the case that numbers have k digits is the sum a 0 + a 3 + . . . + a 9 k , which is, by the "root of unity filter" theorem, 3 P k ( 1 ) + P k ( ω ) + P k ( ω 2 ) Where 1 , ω , ω 2 are the three complex cubic roots of unity. Summing up from 1 to 6 gives k = 1 ∑ 6 3 P k ( 1 ) + P k ( ω ) + P k ( ω 2 ) recalling that 1 + ω + ω 2 = 0 and that ω k = ω k ( m o d 3 ) , we can easily find all these values:
3 5 6 − 2 + 3 5 5 + 1 + 3 5 4 − 1 + 3 5 3 − 2 + 3 5 2 − 1 + 3 5 + 1 = 6 5 1 0