 What's up guys Mike Dakota here. I haven't done a spodge video in a long time So I'm gonna do this one of the problems I solved. It's like the next problem. I think it was the arithmetic progression I don't think I did that yet. I'm kind of like jumping over one after the other one. Yeah Complete the series. All right. So basically, um, you have an arithmetic progression arithmetic progression is basically like if you add you're just adding the same same number over and over again So in this case like one three five seven nine here. We're just adding two every single time, right? So one plus two is three three plus two is five five plus two seven seven plus two to nine Right. They all have a common difference Okay, so now our job is simple. Um, you're given the third term and Then the third to last term and then the sum of the series So now you need to print the length of the series and the series So you have to print the length of the series and the series. So here we have three eight fifty five so the The third to last the third term is three. So we have one two three The third to last term as you can see in the end is eight. That's right So that's eight and then the total sum is 55 Right, so then that's the sum of all these numbers 55 So basically our job is just given these third term third to last and total sum We're just gonna reconstruct the whole array So we just have to print the the length of the array and then the whole array All right, so I'm just gonna explain my solution because Kind of got a seed in the first Half so it's not that difficult. Yeah, I just brute-forced. All right So here I read in the number of test cases and I did t minus minus So here I'm gonna read in x y and z. So x is the third term y is the third to last z is the Total sum right so what do I do first? Well first I'd subtracted the Third to last term from the third term. So I did f is equal to y minus x, okay? And then I had this number called n is equal to six So that's just six and then what I did was I had a number a one is equal to zero So this is gonna represent like the first term. Okay, so then what I do I basically just brute-forced every single Possible number common difference that you could possibly have right so like from like I don't know up to One million right so I'm just like going through all the possible Difference common differences you could possibly have right and then what am I gonna do all right? So I'm gonna take the difference between the six so the difference between the third to last term in The third term and then divide it by n minus 5 and why do I do that? So I could actually show you guys why I do that Trusty here Real quick If you like if you if you look at it, you'll understand why so like let's say we had like six numbers 1 2 3 4 5 6 right and Let's see actually, let's go back. Let's go back to the example. Okay Okay, so let's say we have three which is the third term There's ten numbers right three and then third elastases Was a three eight eight? So one two three four five six seven eight Nine ten actually, let me just clear this one. So one two three four five six seven eight nine ten So this is eight is third elast and this is the third term. Okay, so what am I gonna do? Let's go back to my solution That I did Which is kind of a lousy solution, but it does work. All right, so here What I'm gonna do is I'm going to brute force all the possible possible Common differences that you could possibly have for each between each number. So between each adjacent number We check this and this right so I'm gonna brute force every single possible Combination I could possibly have so here. Um, what I'm going to do is I'm going to take the difference between the third till Third elast term and the third term. So y minus x So what does that do that takes this third to last term eight and then I'm gonna so this third to last term Eight as of track the third term, which is three which gives us five, right? Then what am I gonna do? I'm gonna take this number and I'm gonna divide it by n minus five So what does that do? So if I take this number five and I divide it by n minus five so currently there are there are The common difference that you possibly have here currently is That we have here is Let's see. I Think I did it because Yeah, okay, so I did did n minus five because So originally I put six because six is like Let's say we're guessing that six and then we're just going to go through like all the possible numbers from like the common differences between six to like a Million right so then the reason why I do n minus five is because if you take five and divide it by five You get one so that's gonna give us the common difference between these two these two these two So right so this will be plus one plus one plus one plus one plus one Right, so that gives us one that gives that because it gives us that common difference And then I'm gonna set my Third term and I subtract two times this difference. So what does that do? So this third term right? Three minus two times the common difference of one so two times one is just gonna bust one So this is gonna give us the first term right So if I take have the third term and I subtract by two times the common difference, I'm gonna get the first term So that's what helps you right? Okay, now what I'm gonna do is I'm going to check the Summation and see if it actually equals to the total sum so I know this is kind of really strange but this is like a decent equation so like a You might think that this is like really difficult, but this is basically what I'm doing is I'm just plugging into the formula so I'm doing like two times by the first term plus n minus one times by D so this is gonna give us the Summation of the Yeah, so it's basically I'm doing n times I'm basically doing this equation that does the common difference given the common difference and you just check it You can actually search it up. So some of arithmetic progression formula So yeah, this is a this is the formula When the last term is not given so what are you doing is you're taking the first term two times by the first term plus n minus one which is like the number of Numbers you have and then multiply by the common difference D You add them up and then you multiply by n you divide by two. So that's like the summation formula So I'm just checking that to see if that works Right. So if this does work and it's equal to the total sum of Z So remember Z is the total sum that they gave us so that's works and I just break and when I break I just print out the number and I just print out each common difference So print out n with the number of numbers and I just gonna I'm just gonna loop through from one to n And I'm just gonna add by the common difference. So that's basically what I'm doing here is that Once I have like the common difference, I'm just loop from here to the end of n Right, and I'm just gonna add one every time. So I have one and I'm a plus one So that's gonna be two and I plus one and I get me three plus one get me four so on and so forth. It's how I reach n So that's basically how I did this problem What I'm doing is I'm just going to go boot force and go through every single possible number of values of n to infinity You get the common difference by dividing it by n minus five, right? Because if you're going to assume you divide by n minus five from third to third to last term you get each each the common difference here Right, and then what I'm doing is I'm just gonna find the first term by subtracting two times the common difference from the third term So three two three minus two times common difference the first term is going to give us the one and then from there on I'm just going to just check if the this whole equation is right Like the summation of arithmetic progression is actually equal to our and some if it is I break and I just start Printing out the common difference again, but otherwise I just yeah, that's it So in the end you should be able to get your value if you go through every single possible number of values of one to six to Infinity or not six infinity six to two a million because the constraints are a million. Yeah This is how I did the problem. It's kind of messy. You might find a different a better way to do this problem But yeah, very calm scribe. I'll check you guys later. Peace