1
u/A_BagerWhatsMore 2d ago
So 100x99+98x97…
Is there a way to speed that up?
Two copies 100^2 +98^2… is 100+98… too big
99^2+97^2… is 99+97… too small
Add them together and 2x+50=sum of first 100 squares.
So x= (sum of first 100 squares -50)/2
sum of squares is what n(n+1)(2n+1)/6? (Yes)
So ((100(101)(201)/6)-50)/2) which I would need paper for.
1
u/PsychologicalLie2163 2d ago
I've not thought too deeply about it but could you use factorials?
If n=100, then 100x99 is the same as n! / (n-2)!. Then I guess you sum over all even integers between 1 and n?
1
u/jsundqui 2d ago edited 2d ago
100 * 99 + 98 * 97 + ...
= Sum [n=1 to 50] {2n(2n-1)}
= 4 * Sum { n2 } - 2 * Sum { n }
= 4/6n(n+1)(2n+1) - n(n+1)
n=50:
= 4/6 * 50 * 51 * 101 - 50 * 51 = 169150
2
u/Competitive_Try_330 2d ago
It's 100 * 99 + 99 * 98 + 98 * 97 + 97 * 96+...
1
u/notsaneatall_ 2d ago
99 X 100+98 X 100+98 X 97+... has a higher sum. I don't think what you wrote is the highest
2
u/Competitive_Try_330 1d ago
Sorry, I made it a bit unclear. I did not try to provide an optimal solution. I just wanted to state that each number appears twice in the sum. Have not thought about the optimal solution too much yet
1
u/Icy-Landscape-4796 1d ago
what you've written is much closer but not quite optimal.
1
u/notsaneatall_ 1d ago
I never said what I wrote was optimal, I was pretty sure it wasn't.
I suspect the optimal sequence is something like 2,4,6...100,99,97,95,93...1 or something like that
0
u/jsundqui 2d ago
I know that's what I calculated
2
u/Icy-Landscape-4796 1d ago
no? you've missed out that each number is in two products (except a1 and a100)
1
1
u/Ximaths 1d ago
338151.Permutation: 1, 3, 5,…, 99, 100, 98,…., 4, 2.
1
u/Erwins-Cat 4h ago
had to scroll far to far to find this solution...
for all others, why this is a better way than just sorting 1, ... , 100: two elements are multiplied only once: a_1 and a_100. All other elements are used twice in multiplication. Puttint 100 to a_1 or a_100 means you are not using the 100 with full potential for multiplication, you wasted it once. The upper algo makes sure that all larger numbers used twice and only the lowest numbers, 1 and 2, are used once.
1
u/Ancient_Eggplant_123 1d ago edited 1d ago
If the answered is S than take 2S. Now start from 100 and let's say it is paired with y. Then you write this as 100×(100 -d) where d is the distance from 100 to y. Continue for every number till you reach 1. When I reach y I should write it as y×(y+d). When I pair all terms I get 1002 + 992.... and terms like (d×y - d×100)=d×(y - 100) which will be negative for every pair. Here I use 100 for this example generally it is x and y pairs. This can be used to prove that the optimal is 100×99+98×97.... since the minimum for the other terms it holds that d ×(x-y)=<-1 with y>x and d positive.
1
u/Sarah-Croft 1d ago
You can show by induction that the best permutation is given by inserting the next value n in the middle of the sequence, between n-1 and n-2. Takes a bit of algebra, but you can show that if a better permutation existed, you could remove n and get a better sum than the optimal for n-1, which is a contradiction. For this you can write the adjacent values to n as n-a and n-a-b for positives a and b. Then the sum with n removed would be a²+ab-2 ≥ 0 greater than the optimal, being zero when a=b=1.
1
1
u/RhubarbNo8040 1d ago
x(x-1) = (xC2)*2
Hence the value of 100x99 + 99x98 + ….
= 2 x (summation of nC2) for 2 to 100.
=(k-1)(k)(k+1)/3 for k = 100
You need to subtract the value of k=1 (ie 0).
I think this approach is faster if you revise Basic summations
2
u/Icy-Landscape-4796 1d ago
338,151. starting from the center you want 100 to paired with 99 and 98. 99 should be paired with next highest 97 (and 100). 98 should be paired with next highest 96. that gives this formula: sum (3 to 99) n(n-2) + 100(99+98) with sum of squares and a calculator that gives 338151