Sum of GCDs

A positive integer n n is called ingenious if m = 1 n gcd ( m , n ) \displaystyle\sum_{m=1}^{n} \gcd (m,n) is a prime. Find the number of ingenious integers between 3 3 and 100 100 (inclusive).

Details and assumptions

  • You may refer to this list of primes .

  • As an explicit example, when n = 3 , n=3, we have m = 1 3 gcd ( m , 3 ) = gcd ( 1 , 3 ) + gcd ( 2 , 3 ) + gcd ( 3 , 3 ) = 5 , \displaystyle\sum_{m=1}^{3} \gcd (m, 3) = \gcd (1, 3) + \gcd (2, 3) + \gcd (3, 3)= 5, which is a prime.

  • This problem was inspired by IMOSL 2004 N2 .


The answer is 7.

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.

7 solutions

Define f ( x ) = i = 1 x gcd ( i , x ) . f(x) = \displaystyle \sum_{i=1}^{x} \gcd (i,x).

Lemma 1: Let a , b a,b be two coprime positive integers. Then for all 1 m a , 1 n b , 1 \leq m \leq a, 1 \leq n \leq b, there exists a unique 1 r a b 1 \leq r \leq ab such that gcd ( r , a b ) = gcd ( m , a ) gcd ( n , b ) . \gcd (r, ab)= \gcd (m,a) \gcd (n, b).

Proof: Consider the system of congruencies { x m ( m o d a ) x n ( m o d b ) . \begin{cases} x \equiv m \pmod{a} \\ x \equiv n \pmod{b}. \end{cases}
By CRT, this system has a unique solution mod a b , ab, i.e. x r ( m o d a b ) x \equiv r \pmod{ab} for some 1 r a b . 1 \leq r \leq ab. Then, note that gcd ( r , a b ) = gcd ( r , a ) gcd ( r , b ) = gcd ( m , a ) gcd ( n , b ) , \begin{array}{lcl} \gcd (r, ab) & = & \gcd (r, a) \gcd (r, b) \\ & = & \gcd (m, a) \gcd (n, b), \end{array} where we have used the fact that gcd ( p , q r ) = gcd ( p , q ) gcd ( p , r ) \gcd (p, qr)= \gcd (p,q) \gcd (p,r) for all coprime integers q , r q,r and the division algorithm. Conversely, if gcd ( r , a b ) = gcd ( m , a ) gcd ( n , b ) , \gcd (r, ab)= \gcd (m,a) \gcd (n,b), r r must satisfy r m ( m o d a ) , r n ( m o d b ) , r\equiv m \pmod{a}, r \equiv n \pmod{b}, so r r is unique. \blacksquare


Lemma 2: f ( a b ) = f ( a ) f ( b ) f(ab)= f(a)f(b) for all coprime positive integers a , b . a, b.

Proof: Note that \begin{array}{lcl} f(a)f(b) & = & \left( \displaystyle \sum_{i=1}^{a} \gcd (m, i) \right) \left( \displaystyle \sum_{j=1}^{b} \gcd (n, j) \right) \\ & = & \displaystyle \sum_{\substack{1 \leq i \leq a \\ 1 \leq j \leq b}} \gcd (i, a) \gcd (j, b) \\ & = & \displaystyle \sum_{1 \leq r \leq ab} \gcd (r, ab) \\ & = & f(ab), \end{array} where the last step follows from lemma 1.


Lemma 3: If p p is a prime and k N , k \in \mathbb{N}, f ( p k ) = p a 1 ( a ( p 1 ) + p ) . f \left( p^k \right) = p^{a-1} (a(p-1)+p).

Proof: Note that the only divisors of p k p^k are of the form p x p^x for some x Z + . x \in \mathbb{Z^+}. For any divisor of the form p x , p^x, we get precisely φ ( p k p x ) \varphi \left( \dfrac{p^k}{p^x} \right) numbers n n between 1 1 to p k p^k such that gcd ( n , p k ) = p x . \gcd \left(n, p^k \right) = p^x. Using these facts, we can evaluate the sum as f ( p k ) = 0 x k p x φ ( p k x ) = 0 x < k p k 1 ( p 1 ) + p k = p k 1 ( k ( p 1 ) + p ) , \begin{array}{lcl} f\left(p^k\right) & = & \displaystyle \sum_{0 \leq x \leq k} p^x \varphi \left( p^{k-x} \right ) \\ & =& \displaystyle \sum_{0 \leq x < k} p^{k-1} (p-1) + p^k \\ & = & p^{k-1} (k(p-1)+p), \end{array} where we have used the well known fact φ ( p k x ) = p k x ( 1 1 p ) = p k x 1 ( p 1 ) . \varphi \left ( p^{k-x} \right ) = p^{k-x} \left( 1 - \dfrac{1}{p} \right ) = p^{k-x-1} (p-1). \blacksquare


Using these lemmas, if n n is composite, n n cannot be ingenious. If n n is prime, f ( n ) = 2 n 1. f(n)= 2n-1. So for n n to be ingenious, both n n and 2 n 1 2n-1 have to be primes. A quick search through the list shows that there are 7 \boxed{7} such numbers between 3 3 and 100 , 100, which is our answer. We can omit the primes > 3 >3 which are 2 ( m o d 3 ) , \equiv 2 \pmod{3}, which makes the search faster.

P.S: This solution is moreorless along the lines of the original ISL problem. I was thinking of a more direct solution. Unfortunately it didn't work.

Sreejato Bhattacharya - 7 years, 2 months ago

-.-

Cedric Tan - 7 years, 2 months ago

SO CHIM

Cedric Tan - 7 years, 2 months ago

Function is equal to sum(d*euler totient of (n/d)) for every divisor d of N.

Daanish bansal - 2 years, 11 months ago
Rahul Gautam
Apr 8, 2014

I did it manually 3,7,19,31,37,79,97 are such numbers

Isn't that a bit too tedious? Note that this isn't a computer science problem.

Sreejato Bhattacharya - 7 years, 2 months ago

Log in to reply

I did it as a computer science problem too. . . quick brute force program... I like the number theory approach as well though.

Danny Whittaker - 7 years, 2 months ago

Log in to reply

Same here

Sinjini Das - 7 years, 2 months ago

It is very easy if you do a case work.. If n is the prime number, then you have to check if 2n-1 is a prime or not. This hardly takes 2-3 minutes with a list of primes in front of you.

Pankaj Joshi - 6 years, 11 months ago
Melanka Saroad
Apr 9, 2014

Sreejato Bhattacharya 's lemma proves to be false for b=12 and a=6. The lemma is true if b=an, where gcd(a,n)=1. Generally speaking if f(n) if the sum of gcd(m,n) where m<=n, then f is a multiplicative number theoretic function, i.e f(a,b)=f(a)f(b) whenever gcd(a,b)=1 and f(1)=1.

This would work better as a direct comment on his solution.

@Sreejato Bhattacharya Thoughts?

Calvin Lin Staff - 7 years, 2 months ago

Log in to reply

Oh well, I should have been more careful while writing my solution. The idea about dividing the numbers from 1 1 to b b into b / a b/a intervals fails. I was looking for a more direct solution, but now that I understand it probably doesn't exist, I'll have to change my solution. I am correcting my solution, which will go along the lines of the original ISL problem. Note that luckily this doesn't change the answer.

Sreejato Bhattacharya - 7 years, 2 months ago

How to prove that if n isn't a prime number, there isn't any solution for (m,n) that will fulfill the condition?

Kenneth Anderson - 7 years, 1 month ago
Shyan Akmal
Apr 8, 2014

We use two lemmas that we cite without proof.

Lemma 1: For an arbitrary function f ( n ) f(n) defined over the naturals, we have k = 1 n f ( gcd ( n , k ) ) = d n f ( d ) φ ( n d ) \displaystyle \sum_{k=1}^nf(\gcd(n,k)) = \sum_{d|n}f(d)\varphi\left(\frac{n}{d}\right) where φ ( n ) \varphi(n) is the euler totient function.

Lemma 2: The dirichlet convolution of two multiplicative functions is multiplicative.

In other words, if f ( n ) f(n) and g ( n ) g(n) are multiplicative, then h ( n ) = d n f ( d ) g ( n d ) h(n) =\displaystyle \sum_{d|n}f(d)g\left(\frac{n} {d}\right) is a multiplicative function.

Now, the given function is just what happens when our f ( n ) f(n) in lemma 1 is equal to n n .

Thus, we get m = 1 n gcd ( m , n ) = d n d φ ( n d ) . \displaystyle \sum_{m=1}^n\gcd(m,n) = \sum_{d|n}d\varphi\left(\frac{n}{d}\right). Since the latter is function is multiplicative by lemma 2 , it suffices to check the primes.

We now want to find the number of primes p p between 3 3 and 100 100 such that 2 p 1 2p-1 is also prime. Note that such primes must be congruent to 1 m o d 6 1 \bmod 6 . Doing casework we get the correct answer of 7 7 .

This sum is the same as the sum of d*phi(n/d) over all divisors of n. If we divide this sum by n we get. the sum of phi(d)/d for all divisors of n. When we expand this in terms of primes we get something that is factorable. It factors as the product of ((m(p-1)+p)/p) over all p that divide n, and where m is the maximum power of p that divides n. Now to get back the original sum we multiply this product by n to get the product of ( p^(m-1))(m(p-1)+p) it is obvious that this can only be prime if m=1 and there is only one prime in the product. So n must be a prime number. In this case the product reduces to just evaluating (p^(1-1)) ((p-1)+p). So this whole thing reduces down to 2p-1. At this point we simply need to check how many primes less than one hundred have the property that twice them minus 1 is also prime. We obtain the list 3,7,19,31,37,79,97, for a total of 7 numbers.

Kenny Lau
Sep 9, 2014

java code:

public class brilliant201409091923{
    public static void main(String[] args){
        int count = 0;
        for(int i=3;i<=100;i++){
            int sum = 0;
            for(int j=1;j<=i;j++){
                sum += gcd(j,i);
            }
            if(isPrime(sum)){
                count++;
            }
        }
        System.out.println(count);
    }
    private static int gcd(int a,int b){
        if(a==0) return b;
        return gcd(b,Math.abs(a-b));
    }
    private static boolean isPrime(int p){
        for(int i=2;i<=Math.sqrt(p);i++){
            if(p%i==0) return false;
        }
        return true;
    }
}

output:

7
Press any key to continue . . .
Masba Islam
May 4, 2014

Python code:

from fractions import gcd

def checkprime(n):

s=0

for i in range(2,n/2):

    if n%i==0:

        s=s+1

if s==0:

    return 0

else:

    return 1

count=0

for n in range(3,101):

s1=0

for m in range(1,n+1):

    p=gcd(m,n)

    s1=s1+p

if checkprime(s1)==0:

    count=count+1

print count

This isn't a CS problem.

Sreejato Bhattacharya - 7 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...