What is the sum of all positive integers less than 1 0 4 which are relatively prime to 1 0 4 ?
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.
That is basically the way I did it, although I am happy to learn about Euler's totient function! I didn't realize at first that 1 is counted as coprime to every number, so I originally had 19,999,999.
I had basically the same idea. 10^4 = 2^4 5^4 All numbers less than 10^4 coprime to that can contain no 2 or 5. All numbers divisible by 2 or 5 cycle by groups of 10 numbers, and only those ending in 1,3,7,9 are coprime. Each group adds 1+3+7+9=20 plus its offset from 0. That's 20 10^3=20000 for the last digit and S=0+10+...+9990=9990*1000/2=4995000 for the offsets. So 5015000. Clearly I'm missing something.
Log in to reply
I feel that your approach might be closer to Andy Hayes' solution. See the correct version there.
Log in to reply
Ya, I figured it out after I posted, but couldn't find a way back to the question. I just missed the part where the collective sum of offsets from 0 happens 4 times. Got 20,000,000.
Again, if you know what the phrase “relatively prime to 10^4” means then you know how to work to the answer. If not, then the question is frustrating and abstruse... and reading your answer does not inform.
Seems easier to not include 10000 since you then get simpler multiplications.
Relevant wiki: Euler's Totient Function
The sum S of all positive integers less than n and relatively prime to n is 2 n ϕ ( n ) ∀ n > 2 .
Proof:
If k ∈ { 1 , … , n − 1 } is relatively prime to n , then so is n − k , so the integers that are being summed up can be combined into 2 ϕ ( n ) pairs whose members sum to n . If n > 2 , 2 n is never relatively prime to n , so we must have pairs { k , n − k } .
Now, a number n with prime factorization
n = p 1 q 1 p 2 q 2 ⋯ p k q k
will have
ϕ ( n ) = n ( 1 − p 1 1 ) ( 1 − p 2 1 ) ⋯ ( 1 − p k 1 )
positive integers less than n that are relatively prime to n . With that in mind, we solve for n = 1 0 4 .
1 0 4 ⟹ ϕ ( 1 0 4 ) ⟹ S = 2 4 × 5 4 = 1 0 4 ( 1 − 2 1 ) ( 1 − 5 1 ) = 4 × 1 0 3 = 2 1 0 4 × 4 × 1 0 3 = 2 × 1 0 7
Excellently done
I think the approach of @Zee Ell approach is best, but here is an alternative approach.
The numbers which are relatively prime to 1 0 4 will satisfy:
n ≡ 1 , 3 , 7 , 9 ( m o d 1 0 ) .
They will be of the forms:
n = 1 0 k + 1 , 1 0 k + 3 , 1 0 k + 7 , 1 0 k + 9
for some integer k , 0 ≤ k ≤ 9 9 9 . Summing all of these integers gives:
S = k = 0 ∑ 9 9 9 ( 1 0 k + 1 ) + k = 0 ∑ 9 9 9 ( 1 0 k + 3 ) + k = 0 ∑ 9 9 9 ( 1 0 k + 7 ) + k = 0 ∑ 9 9 9 ( 1 0 k + 9 ) = k = 0 ∑ 9 9 9 ( 4 0 k + 2 0 ) = 4 0 ( 2 9 9 9 ⋅ 1 0 0 0 ) + 2 0 ( 1 0 0 0 ) = 2 0 0 0 0 0 0 0
Why are all the numbers relatively prime to 10^4 of this form?
Log in to reply
All numbers can be written as the multiple of some number, k, + the remainder when divided by k. So all numbers divisible by 10 are of the form 10k, 10k+1, 10k+2..... 10k+9. So all numbers which are divisible by 2 in this form would be: 10k, 10k+2, 10k+4..... 10k+8. And all numbers divisible by 5 would be 10k, 10k+5. Since trying to divide 2 or 5 into any of the other forms would lead to a remainder. Hence, all the other forms are not divisible by 2 or 5.
Elegant solution...👌
To solve this problem, we find the general formula for the sum of positive integers less than n which are relatively prime to n .
Let gcd ( a , b ) denote the greatest common divisor of two integers a and b .
From the wiki, we know that gcd ( c , d ) = gcd ( c , c − d ) for integers d < c .
In order to make the notation more manageable, let us consider the sequence of integers less than some number n which are relatively prime to n . Let us call this sequence C , and let it be the sequence:
c 0 , c 1 , c 2 , … c ϕ ( n ) − 2 , c ϕ ( n ) − 1
Note that there are exactly ϕ ( n ) ( ϕ ( n ) is the totient function) integers in C by the definition of the totient.
We are now trying to find a closed form for the sum S :
i = 0 ∑ ϕ ( n ) − 1 c i
By definition, gcd ( n , c i ) = 1 for all 1 ≤ i ≤ ϕ ( n ) − 1 (the definition of relatively prime integers). Also by definition, the sequence includes all integers c < n such that gcd ( n , c ) = 1 . We know that gcd ( n , n − c i ) = gcd ( n , c i ) = 1 and that n − c i < n , hence n − c i must be in the sequence C . In fact, it must be true that n − c i = c ϕ ( n ) − 1 − i .
For a concrete example, consider n = 9 . The sequence C would be:
1 , 2 , 4 , 5 , 7 , 8
The sequence has length 6 = ϕ ( 9 ) . It is apparent that 9 − 1 = 8 , 9 − 2 = 7 , 9 − 4 = 5 , 9 − 5 = 4 , 9 − 7 = 2 , 9 − 8 = 1 , which is equivalent to saying that n − c i = c ϕ ( n ) − 1 − i for all c i in C .
We now rewrite C as
c 0 , c 1 , c 2 … n − c 2 , n − c 1 , n − c 0
We can now rewrite S as:
S = i = 0 ∑ ϕ ( n ) c i = c 0 + c 1 + c 2 + … + n − c 2 + n − c 1 + n − c 0 = c 0 − c 0 + c 1 − c 1 + c 2 − c 2 + … + n + n = n + … + n
Where n is repeated exactly 2 ϕ ( n ) times. Hence,
S = 2 n ϕ ( n )
Substituting n = 1 0 4 ,
2 1 0 4 ⋅ ϕ ( 1 0 4 ) = 2 1 0 4 ⋅ 4 0 0 0 = 2 ⋅ 1 0 7
1 0 0 0 0 = 2 4 × 5 4
We are going to going to get the desired sum by subtracting sum of integers less than 1 0 0 0 0 divisible by 2 or 5 from sum of first 9 9 9 9 integers.
It is easy to calculate the sum of first 9 9 9 9 integers: ∑ k = 1 9 9 9 9 k = 2 9 9 9 9 × 1 0 0 0 0 = 9 9 9 9 × 5 0 0 0 .
Next, sum of all even numbers less then 10000:
∑ = 2 + 4 + 6 + 8 + . . . + 9 9 9 8 = 2 ( 1 + 2 + 3 + 4 + . . . + 4 9 9 9 ) = 2 × 2 4 9 9 9 × 5 0 0 0 = 5 0 0 0 × 4 9 9 9 .
Then, sum of all numbers divisible by 5 minus all even numbers in this group equals:
∑ = 1 0 0 0 5 + 1 5 + 2 5 + 3 5 + . . . + 9 9 9 5 = 2 ( 5 + 9 9 9 5 ) × 1 0 0 0 = 1 0 0 0 × 5 0 0 0
(note that there are 1999 numbers divisible by 5 less than 10000, and that 999 of them are even)
Hence, desired sum is:
9 9 9 9 × 5 0 0 0 − 4 9 9 9 × 5 0 0 0 − 1 0 0 0 × 5 0 0 0 = 5 0 0 0 ( 9 9 9 9 − 4 9 9 9 − 1 0 0 0 ) = 5 0 0 0 × 4 0 0 0 = 2 0 , 0 0 0 , 0 0 0
Nice approach. Neat solution.
I solve this by a much simpler way
I first find what numbers are relatively prime to 10000 between 1 to 10 included
I find that 1,3,7,9 are relatively prime to 10000
then I concluded that every even number and also with last digit 5 or 0 are and only not relatively prime to 10000.
It is because, 1 0 0 0 0 = 2 4 × 5 4
every even number has a factor 2, and every number with last digit 5 has a factor 5, and also every number with a last digit 0 has a factor 10, so these number aren't relatively prime to 10000.
so along the first four number , I get 11,13,17,19 and 21,23,27,29 and so on, until 9991,9993,9997,9999.
I add it up by summation
2 1 0 0 0 ( 1 + 9 9 9 1 + 3 + 9 9 9 3 + 7 + 9 9 9 7 + 9 + 9 9 9 9 ) = 2 × 1 0 7
Could you please explain what you mean here:
then I concluded that every even number and also with last digit 5 or 0 are and only relative to 10000
I didn't really get you.
Log in to reply
Oh, I maybe too casual to write this solution, I will write some explanation at the bottom.
Since the factors of 10^4 are 2^4 and 5^4, The numbers relatively prime to 10^4 must be multiples of 2 or 5. We can see that any even number is a multiple of two so instead we can just find the sum of all positive odd integers less than 10^4 and remove any divisible by 5. Those that are divisible by 5 are the ones ending in 5. Thus, our answer can be Sum of Odd Numbers - Sum of Odd Numbers Ending in 5 This becomes 2 5 0 0 0 X 1 0 0 0 0 - 2 1 0 0 0 X 1 0 0 0 0 = 25000000-5000000 which gives a answer of 20000000
Notes: The equation was from the rule that a+(a+k)+(a+2k).....+(a+nk)= 2 ( a + a + n k ) ∗ ( n + 1 )
5000 was the number of odd numbers less than 10^4 and 10000 was (1+9999)
1000 was the number of odd numbers less than 10^4 ending in 5 and 10000 was (5+9995)
As @Zee Ell pointed out we are looking for the sum of numbers below 10⁴ which are not multiples of 2 or 5. We can first add all the odd numbers below 10⁴, and then substract the odd multiples of 5 to get our answer.
As we are interested in the numbers smaller than 10⁴, the last even number we need to consider is 9999, which is the 5000th odd number (x is the 2 x + 1 th odd number). The sum of the first n odd numbers is n² so we get 5000²=25×10⁶. We then need to substract the odd multiples of 5 from that (5+15+25+35...). We can factor out the 5 so we end up with 5(1+3+5+7...) which is 5 times the sum of odd numbers... up to 5 9 9 9 5 =1999, which is the 1000th odd number. So 5× that sum is 5×1000²=5×10⁶. Substract, and we end up with 20×10⁶, or 2×10⁷
General solution
Consider the general case: given a positive integer N > 2 , how much is 1 ≤ d < N , ( N , d ) = 1 ∑ d ? The answer is 2 1 ϕ ( N ) N , where ϕ is the Euler totient function.
Here , ϕ ( 1 0 4 ) = 1 0 3 ⋅ ϕ ( 1 0 ) = 1 0 3 ⋅ ϕ ( 2 ) ⋅ ϕ ( 5 ) = 1 0 3 ⋅ 1 ⋅ 4 = 4 × 1 0 3 , so that the answer is 2 1 ⋅ 4 × 1 0 3 ⋅ 1 0 4 = 2 ⋅ 1 0 7 = 2 0 0 0 0 0 0 0 .
Proof
Observe that if ( N , d ) = 1 then ( N − d , d ) = 1 . (Also, N and N − d are distinct numbers in this case; the only exception would be d = N / 2 but then ( N , d ) = N / 2 > 1 .)
Thus the values to be added come in pairs, and the sum of each pair is d + ( N − d ) = N . The number of pairs is half the number of values to be added; and the number of values to be added is ϕ ( N ) . This immediately gives (number of pairs) ⋅ (sum of each pair) = 2 1 ϕ ( N ) ⋅ N .
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 |
|
[1, 3, 9, 11, 13, 17, 19, 21, 23, 27, 29, 31, 33, 37, ......9971, 9973, 9977, 9979, 9981, 9983, 9987, 9989, 9991, 9993, 9997, 9999]
Log in to reply
Your list includes the values 2 and 5, which are prime but not relative prime to 1 0 4 .
Log in to reply
Thanks Arjen. I see where I made the mistake in my coding
results[1:-1] should be x = results[1:] b[1:-1] should be b[1:]
This seemingly tedious chore can be done in two simple steps using two sums of consecutive odd numbers.
1 0 4 = 2 4 x 5 4
Every number less than 10,000 that is not relatively prime has a factor of 2 or 5. Those numbers consist of the even numbers and odd multiples of 5.
The problem can be solved directly by summing the odd numbers and subtracting the sum of the odd multiples of 5, both using the fact that the sums of consecutive odd numbers are perfect squares.
There are 5000 positive odd integers less than 10,000. The sum of those is 5 0 0 0 2 = 25,000,000.
All that is necessary is to subtract the odd multiples of 5 to get the answer.
The odd multiples of 5, 5 + 15 + ,,, + 9995 = 5 x ( 1+ 3 +...+ 1999 ). Again a sum of consecutive odd numbers.
There are 1000 odd multiples of 5 less than 1 0 4 so 1+ 3 +...+ 1999 = 1000^2 = 1,000,000
The sum of the odd multiples of 5 less than 1 0 4 is 5 x 1,000,000 = 5,000,000
The solution is 25,000,000 - 5,000,000 = 20,000,000
This was a simple problem. The only numbers NOT coprime with 10,000 are the odd integers with the exception of those divisible by 5. So sum all the odd numbers from 1 to 9999. Then sum all numbers 5+15+25+.....+9995 and subtract the second sum from the first.
So, all odd integers not divisible by 5 are coprime to 10000? That is a neat observation indeed. How did you get this result?
Problem Loading...
Note Loading...
Set Loading...
Since 1 0 0 0 0 = 1 0 4 = 2 4 × 5 4 , therefore exactly those integers will be
coprime to 10000, which are neither divisible by 2 nor divisible by 5.
Hence, we can get our sum S by applying PIE (the principle of inclusion-exclusion) and the sum of the arithmetic sequence formula:
S = 2 1 0 0 0 0 × 1 0 0 0 1 − 2 × 2 5 0 0 0 × 5 0 0 1 − 5 × 2 2 0 0 0 × 2 0 0 1 + 1 0 × 2 1 0 0 0 × 1 0 0 1 =
= 2 0 0 0 0 0 0 0
Remarks:
1.) For the sake of simplicity, we summed the integers till 10000 (despite the question says < 10000), but we filtered the 10000 out (since it is not coprime to itself), so we got the correct result in the end.
2.) It is not necessary to generalise in order to solve a simple case like this (where we have no more than 2 prime factors). However, in cases where we have (more than) 3 prime factors, we might be better off by using Euler's Totient Function (see the solutions of Alex G and Zach Abueg regarding this).