practice problems pending
Q) Does there exist a sequence of integers a1,a2.... such that for each integer d != 0 there are exactly 2025 distinct pairs of indices i,j for which ai - aj = d?
Answer:
Yes
But how to construct such a sequence?
Before that let me mention that there is nothing special about 2025 in this problem. It could have been any other number.
Let's try a way:
If we target d = 1
Then we can simply have a sequence:
1,2....2026 and we have exactly 2025 pairs of integers with diff = 1.
Now for d = 2:
We already have 2024 such pairs in 2,3...2026, we just need to add one more.
Let's add the number 2028 so that 2026,2028 is the required new pair.
Now for d=3:
We already have 2023 such pairs in 2,3....2026, and 2025,2028 is another. So total 2024.
Just add 2031 so that 2028,2031 is another pair and we are done.
Now for d=4
we have 2022 pairs in the intial block. then 2024,2028. then add 2035 to pair with 2031. And then 2039 for 2035. Now we have met target for d=4.
So basically at each step see what's the current deficit for the current target(go in sequence d= 1,2,3,4) and then add a number to fix that deficit.
But going this way, we are accidentally adding pairs in an unsystematic manner which will be hard to track. Here we have added another pair 2031,2039 which creates d=8 pair.
So this method is quite error prone.
Let's do something else.
Astronomical spacing.
Since the sequence is infinite. We can choose numbers at great differences from each other.
Jump rule: Let's say we are targeting a certain value of 'd'. So we take the largest number which we have right now in our sequence. Multiply by 10. And add 'd' to it. And do it until we have attained 2025 pairs with diff d.
Let's start with only one number in our sequence: 1.
Our target is d=1 having 2025 pairs.
Multiply the biggest number with 10: 1*10
x = 10, add x+d = 11
Now sequence is 1,10,11.
Add 11*10,11*10+1 => 110,111
then
1110,1111
Until you have created 2025 pairs with diff 1.
So far we haven't created any pairs with diff 2.
So once we are done with 2025 pairs with d=1, repeat the same process for d=2.
But if you notice, we accidentally did leave behind pairs with d=9,10,99,100. Let's call them junk numbers.
So once we reach the target of d=9, we will only add 2024 pairs for it. This is something we need to keep track of.
Can we show that when we leave behind a trail of junk numbers, each such junk number can appear at max once?
Let's try.
1. Collision with a past diff
Let's say the current max is M.
In the next step we will add 10M,10M+d where d is our current target.
Addition of these 2 new numbers will create a minimum diff of 10M-M = 9M whereas earlier the maximum diff was M-1.
So addition of these 2 numbers wouldn't create a diff pair which was already there.
2. Collision with a future diff
By the same logic, the minimum diff in the next step will be (10M+1).10-(10M+1) = 90M-9 which is way beyond any current diff.
3. Collision with each other
This is the trickiest part.
When we add x,x+d can they, by subtracting previous numbers, create a duplicate junk number.
Let's say x - y1 = x +d - y2 => y2-y1 = d
So there is a possibility that we can create 2 copies of same diff in a single step.
But that's ok since this can only happen once at max.
So when we start the process for target=d we will just do it 2023 times and not 2024 times.
So essentially:
The astronomical spacing strategy can create 0,1,2 copies of a diff in a single step.
But that can only happen once at max.
So we keep a tally for each diff we have created thus far.
And loop for 2025-that count when we want to hit the target for that d.
Comments
Post a Comment