Coprime Period

0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 0 , 1 period , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , \large\underbrace{0,1,0,1,0,0,0,1,0,1}_{\text{period}}, 0,1,0,1,0,0,0,1,0,1,0,\dots Let n n be a positive integer, and let the function f n : N { 0 , 1 } f_n:\ \mathbb N \to \{0,1\} be defined by f n ( m ) = { 0 gcd ( n , m ) > 1 1 gcd ( n , m ) = 1. f_n(m) = \begin{cases} 0 & \gcd(n,m) > 1 \\ 1 & \gcd(n,m) = 1. \end{cases} That is, f n ( m ) f_n(m) tells us whether m m is coprime to n n or not. If we write out the values of f n , f_n, we get a periodic (repeating) pattern. For instance, the list above gives the values of f 10 f_{10} starting at m = 0 m = 0 ; the pattern repeats itself with period 10.

Consider the function f 1400 f_{1400} . What is its period?


Note: The period is defined as the smallest possible value, that is, the least positive T T such that f n ( m + T ) = f n ( m ) f_n(m + T) = f_n(m) for all integers m m .


The answer is 70.

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.

2 solutions

Arjen Vreugdenhil
Mar 20, 2017

Lemma

If the prime factor decomposition of n n is n = p 1 e 1 p 2 e 2 n = p_1^{e_1} \cdot p_2^{e_2} \cdot \cdots then the period of f n f_n is equal to T = p 1 p 2 . T = p_1 \cdot p_2 \cdots.

Application

In this case, since 1400 = 2 3 5 2 7 , 1400 = 2^3 \cdot 5^2 \cdot 7, the solution is 2 5 7 = 70 . 2 \cdot 5 \cdot 7 = \boxed{70}.


Proof

(1) We show that if there is a p n p|n such that p ∤ T p \not | T , then there exist m m with f n ( m ) = 0 f_n(m) = 0 but f n ( m + T ) = 1 f_n(m+T) = 1 .

Assuming this, let m = q 1 q 2 m = q_1\cdot q_2\cdots be the product of all prime factor of n n that do not divide T T . Then f n ( m ) = 0 f_n(m) = 0 because gcd ( n , m ) = m > 1 \gcd(n,m) = m > 1 . Now suppose that there is some prime factor q gcd ( n , m + T ) q|\gcd(n,m+T) , implying both q n q|n and q ( m + T ) q|(m+T) . The way we defined m m , q q is a prime factor of either T T or m m , but not both. Therefore q q does not divine m + T m+T ; it follows that such a prime number q q does not exist. We conclude gcd ( n , m + T ) = 1 \gcd(n,m+T) = 1 and f n ( m + T ) = 1 f_n(m+T) = 1 .

It follows that T T must be at least a multiple of all prime divisors p 1 , p 2 , p_1,p_2,\dots of n n .

(2) We show that if T = p 1 p 2 T = p_1\cdot p_2 \cdots , then f n ( m ) = f n ( m + T ) f_n(m) = f_n(m+T) for all m m .

If f n ( m ) = 0 f_n(m) = 0 then gcd ( n , m ) > 1 \gcd(n,m) > 1 , which means there is a prime factor p gcd ( n , m ) p|\gcd(n,m) ; this means that p n p|n and p m p|m . From p n p|n and the definition of T T is follows that p T p|T . From p m p|m and p T p|T it follows that p ( m + T ) p|(m+T) . Therefore p gcd ( n , m + T ) p|\gcd(n,m+T) , implying that f n ( m + T ) = 0 f_n(m+T) = 0 as well.

Conversely, suppose that f n ( m ) = 1 f_n(m) = 1 , i.e. gcd ( n , m ) = 1 \gcd(n,m) = 1 . Then no prime factor p n p|n can be a divisor of m m . But if p ∤ m p\not | m and p T p|T then p ∤ m + T p \not | m+T , implying that gcd ( n , m + T ) = 1 \gcd(n,m+T) = 1 and f n ( m + T ) = 1 f_n(m+T) = 1 .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# https://brilliant.org/practice/greatest-common-divisor-lowest-common-multiple-4-c/?p=4

def gcd(*numbers):
    """Return the greatest common divisor of the given integers"""
    from fractions import gcd
    return reduce(gcd, numbers)

def period_n(l):
    s_arr=''
    for i in range(0,len(l)):
        s_arr=s_arr+l[i]
        sp_list=string_.split(s_arr)
        c = 0
        for j in sp_list:
            if j =='':
                c+=1
        if c == len(sp_list):
            break
    return s_arr, sp_list, c

f_target = 1400
string_ = ''
for i in range(f_target):
    if gcd(i,f_target) > 1:
        string_ += '0'
    else:
        string_ += '1'

binarylist=list(string_)
strarr, splitlist, counter = period_n(binarylist)

if counter == len(splitlist):
    if counter == 2:
        print "No repeating substring found in string %r"%(string_)
    else:
        print "Substring %r of period %d (%d times)"%(strarr, len(strarr), counter)
else :
    print "No repeating substring found in string %r"%(string_)

Substring '0101000001010100010100010001010101000101010100010001010001010100000101' of period 70 (21 times)

This would be my coded solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>

#define N 1400

int gcd(int a, int b) {
    if (a < b) return gcd(b,a);
    if (b == 0) return a;
    return gcd(b, a%b);
}

int f(int m) { return gcd(N,m) == 1 ? 1 : 0; }

int is_period(int T) {
    for (int i = 0; i < N; i++)
        if (f(i) != f(i + T)) return 0;
    return -1;
}

int main() {
    int T = 1; while (T < N && !is_period(T)) T++;
    printf("Period: %d\n", T);

    return 0;
}

Arjen Vreugdenhil - 3 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...