Homepage › Solution manuals › Ivan Niven › An Introduction to the Theory of Numbers › Exercise 2.1.50* (Multiple of $n$ which contains only the digits 0 and 1)
Exercise 2.1.50* (Multiple of $n$ which contains only the digits 0 and 1)
Given a positive integer , prove that there is a positive integer that to base ten contains only the digits and such that . Prove that the same holds for digits and , or and , or and , but for no other pair of digits.
Answers
Proof.
- a)
-
First proof.
Assume first that is relatively prime with (i.e. ). Then , therefore
So
and
contains only the digits and in its decimal expansion.
General case: Using the decomposition of in prime numbers, write , where . By the preceding argument, there is a multiple of such that contains only the digits and .
Then
Therefore is such that , and
contains only the digits and .
Second proof (found on the net, math.stackexchange.com, author nonuser)
Let
So, among two must have the same remainder modulo , say and and . Thus
- b)
- If , where contains only the digits and in its decimal expansion, then , and contain only the digits and , or and , or and .
- c)
- If the same hold for another pair of digits , then , where contains only the digits and . Since the last digit of is , or .
Note: If (i.e. if ), is a shorter solution
(we don’t obtain always the shortest solution : if , then the algorithm of part (a) gives , but is the shortest solution).
This gives the following code, written in Sage
phi = euler_phi def exo50(n): k ,l = 0, 0 while n % 2 == 0: k += 1 n //= 2 while n % 5 == 0: k += 1 n //= 5 if gcd(n,3) == 1: return 10^(k + l) * ((10^phi(n) - 1) // 9) else: return 10^(k+l) * ((10^(n * phi(n)) - 1) // (10^phi(n) - 1))
We test the program:
l = [] for n in range(1,22): m = exo50(n) if exo50(n) % n != 0: print(’error’) print(n, m) (1, 1) (2, 10) (3, 10101) (4, 100) (5, 10) (6, 101010) (7, 111111) (8, 1000) (9, 1000001000001000001000001000001000001000001000001) (10, 100) (11, 1111111111) (12, 1010100) (13, 111111111111) (14, 1111110) (15, 101010) (16, 10000) (17, 1111111111111111) (18, 10000010000010000010000010000010000010000010000010) (19, 111111111111111111) (20, 1000) (21, 100000000000100000000000100000000000100000000000100000000000100000000000\ 100000000000100000000000100000000000100000000000100000000000100000000000\ 100000000000100000000000100000000000100000000000100000000000100000000000\ 1000000000001000000000001)
This code can be improved by shortening if is a multiple of .
The second proof, mathematically more elegant, is less efficient.