A positive integer n is called ingenious if m = 1 ∑ n g cd ( m , n ) is a prime. Find the number of ingenious integers between 3 and 1 0 0 (inclusive).
Details and assumptions
You may refer to this list of primes .
As an explicit example, when n = 3 , we have m = 1 ∑ 3 g cd ( m , 3 ) = g cd ( 1 , 3 ) + g cd ( 2 , 3 ) + g cd ( 3 , 3 ) = 5 , which is a prime.
This problem was inspired by IMOSL 2004 N2 .
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.
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.
-.-
SO CHIM
Function is equal to sum(d*euler totient of (n/d)) for every divisor d of N.
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.
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.
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.
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?
Log in to reply
Oh well, I should have been more careful while writing my solution. The idea about dividing the numbers from 1 to b into 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.
How to prove that if n isn't a prime number, there isn't any solution for (m,n) that will fulfill the condition?
We use two lemmas that we cite without proof.
Lemma 1: For an arbitrary function f ( n ) defined over the naturals, we have k = 1 ∑ n f ( g cd ( n , k ) ) = d ∣ n ∑ f ( d ) φ ( d n ) where φ ( n ) is the euler totient function.
Lemma 2: The dirichlet convolution of two multiplicative functions is multiplicative.
In other words, if f ( n ) and g ( n ) are multiplicative, then h ( n ) = d ∣ n ∑ f ( d ) g ( d n ) is a multiplicative function.
Now, the given function is just what happens when our f ( n ) in lemma 1 is equal to n .
Thus, we get m = 1 ∑ n g cd ( m , n ) = d ∣ n ∑ d φ ( d n ) . 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 between 3 and 1 0 0 such that 2 p − 1 is also prime. Note that such primes must be congruent to 1 m o d 6 . Doing casework we get the correct answer of 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.
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 . . .
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.
Problem Loading...
Note Loading...
Set Loading...
Define f ( x ) = i = 1 ∑ x g cd ( i , x ) .
Lemma 1: Let a , b be two coprime positive integers. Then for all 1 ≤ m ≤ a , 1 ≤ n ≤ b , there exists a unique 1 ≤ r ≤ a b such that g cd ( r , a b ) = g cd ( m , a ) g cd ( n , b ) .
Proof: Consider the system of congruencies { x ≡ m ( m o d a ) x ≡ n ( m o d b ) .
By CRT, this system has a unique solution mod a b , i.e. x ≡ r ( m o d a b ) for some 1 ≤ r ≤ a b . Then, note that g cd ( r , a b ) = = g cd ( r , a ) g cd ( r , b ) g cd ( m , a ) g cd ( n , b ) , where we have used the fact that g cd ( p , q r ) = g cd ( p , q ) g cd ( p , r ) for all coprime integers q , r and the division algorithm. Conversely, if g cd ( r , a b ) = g cd ( m , a ) g cd ( n , b ) , r must satisfy r ≡ m ( m o d a ) , r ≡ n ( m o d b ) , so r is unique. ■
Lemma 2: f ( a b ) = f ( a ) f ( b ) for all coprime positive integers 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 is a prime and k ∈ N , f ( p k ) = p a − 1 ( a ( p − 1 ) + p ) .
Proof: Note that the only divisors of p k are of the form p x for some x ∈ Z + . For any divisor of the form p x , we get precisely φ ( p x p k ) numbers n between 1 to p k such that g cd ( n , p k ) = 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 ) , where we have used the well known fact φ ( p k − x ) = p k − x ( 1 − p 1 ) = p k − x − 1 ( p − 1 ) . ■
Using these lemmas, if n is composite, n cannot be ingenious. If n is prime, f ( n ) = 2 n − 1 . So for n to be ingenious, both n and 2 n − 1 have to be primes. A quick search through the list shows that there are 7 such numbers between 3 and 1 0 0 , which is our answer. We can omit the primes > 3 which are ≡ 2 ( m o d 3 ) , which makes the search faster.