All the digits of the positive integer N are either 0 or 1 . For N ≤ 1 0 3 0 , let S be the number of N such that N divisible by 3 7 . What is the sum of digit of S ?
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.
The solution to this problem is easy if you know the solution for part one, The Dividing Path - 1. There is a special trick discovered by Calvin Lin in finding out whether a positive integer is divisible by 37. For more information see the solution of part 1 and (http://www.thirty-seven.org/misc/divisibility.html).
For positive integer N with either 0 or 1 as digits, the solution is first to find the n 0 number of 1 ′ s of all the 0 m o d 3 digits of N , n 1 of 1 m o d 3 digits, and n 2 of 2 m o d 3 digits. Then, if a = n 0 + 1 0 n 1 + 2 6 n 2 and a ≡ 0 m o d 3 7 or a is divisible by 3 7 , then N is divisible by 3 7 .
My simple Python script for the problem is:
To find n 0 , n 1 and n 2
If a ≡ 0 m o d 3 7 , the find S the number of N with these specific n 0 , n 1 and n 2 . That is S = 1 0 C n 0 1 0 C n 1 1 0 C n 2 .
Add all the S 's together and then find its digital sum.
from math import factorial as f
def comb10(n): # Computing 10Cn
x = f(10)/f(n)/f(10-n)
return x
S = 0
for i in range(1,11):
for j in range(1,11):
for k in range(1,11):
a = 26*i + 10*j + k
if a % 37 == 0:
n = comb10(i)*comb(j)*comb(k)
S += n
print i, j, k, n, S
The answer is S = 3 9 5 3 1 4 5 9 and its digital sum is 3 9 .
Problem Loading...
Note Loading...
Set Loading...
Well the solution to this problem is pretty easy with dp. Here's the code for the same: