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 n , prove that there is a positive integer m that to base ten contains only the digits 0 and 1 such that n m . Prove that the same holds for digits 0 and 2 , or 0 and 3 , , or 0 and 9 , but for no other pair of digits.

Answers

Proof.

a)
First proof.

Assume first that n is relatively prime with 10 (i.e. 2 n , 5 n ). Then 1 0 ϕ ( n ) 1 ( mod n ) , therefore

k = 0 n 1 1 0 ( n ) n 0 ( mod n ) .

So

n m = k = 0 n 1 1 0 ( n ) = 1 0 ( n ) 1 1 0 ϕ ( n ) 1 ,

and

m = 100 0 ϕ ( n ) 100 0 ϕ ( n ) 100 0 ϕ ( n ) 1 1

contains only the digits 0 and 1 in its decimal expansion.

General case: Using the decomposition of n in prime numbers, write n = 2 k 5 l n , where n 10 = 1 . By the preceding argument, there is a multiple m = k = 0 n 1 1 0 ( n ) of n such that m contains only the digits 0 and 1 .

Then

n 5 k 2 l n = 5 k 2 l ( 2 k 5 l n ) = 1 0 k + l n 1 0 k + l m .

Therefore m = 1 0 k + l m = 1 0 k + l k = 0 n 1 1 0 ( n ) is such that n m , and

m = 100 0 ϕ ( n ) 100 0 ϕ ( n ) 100 0 ϕ ( n ) 1 1 00 0 k + l

contains only the digits 0 and 1 .

Second proof (found on the net, math.stackexchange.com, author nonuser)

Let

a k = 111 11 k = 1 0 k 1 9 .

So, among a 1 , a 2 , , a n + 1 two must have the same remainder modulo n , say a i and a j and i > j . Thus

n a i a j = 1 0 i 1 0 j 9 = 1 0 j 1 0 i j 1 9 = 111 11 i j 000 00 j .

b)
If n m , where m contains only the digits 0 and 1 in its decimal expansion, then n 2 m , n 3 m , , n 9 m , and 2 m , 3 m , , 9 m contain only the digits 0 and 2 , or 0 and 3 , , or 0 and 9 .
c)
If the same hold for another pair of digits i , j , then 10 m , where m contains only the digits i and j . Since the last digit of m is 0 , i = 0 or j = 0 .

Note: If n 30 = 1 (i.e. if 2 n , 5 n , 3 n ), m = 1 0 ϕ ( n ) 1 9 is a shorter solution

(we don’t obtain always the shortest solution : if n = 3 , then the algorithm of part (a) gives m = 101010 , but m = 111 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 m if m is a multiple of 3 .

The second proof, mathematically more elegant, is less efficient.

User profile picture
2024-08-05 08:54
Comments