 What's up guys, my name is Michael and welcome to my YouTube channel today. We are going to go over this problem called what's next. Basically you're given three numbers a one a two and a three and you just have to determine whether is an arithmetic progression or a geometric progression. And it's guaranteed that's one or the other. And, um, yeah, the last line is when all the three values are zero. So that's, that's when you break through the loop. Okay. And, um, yeah. And then basically that's it. Just print whether it's an arithmetic progression or geometric progression. And then the next, uh, next thing you're printing is basically the, the next member of the sequence. So the next, the next value of the sequence. So in this, in this case, we have four, seven, 10. We know this is an arithmetic progression based on the definition of arithmetic progressions and, uh, because we're adding three every time. So four plus three is seven, seven plus three is 10, 10 plus three is 13. And that's why the output is 13. In the other one, we have two, six and 10, uh, two, six and 18. We know this is a geometric progression because we're multiplying three every time. Two times three is six, six times three is 18, 18 times three is 54. Right. And that's why the next pro next value is 54 because 18 times three is 54. Okay. And that's basically the gist of the problem. You just have to determine if it's an arithmetic progression or not. So if we want to write this down, let's say I have a one, a two, a three, we just have to determine a four, right? And if there's, if it's an arithmetic progression, we're adding by some number X every single time. So this would be an arithmetic progression. A four will just be a three plus X. And if it's a geometric progression, you're multiplying by some number. You're multiplying by some X. So we would multiply by some X value and multiply by some X value. And then a four is multiplying is a three multiplied by an X value. So yeah, that's, that's basically the definition of arithmetic progression and geometric progression. And I'm going to explain the code. So guys, I have not actually done this problem before with, uh, in C plus plus. So I'll do it with you guys. Okay. So we know in arithmetic progression is if they, each of the sums, if you add a value to the first value, it equals the second one. And if you add the same value to the second one equals a third value. So there are differences between them that have to be the same. So if a one, um, eight, if a two minus a one is equal to a three minus a two. Yeah. If a two minus a one is equal to a three minus a two, then we're going to see out arithmetic progression and then a space. And then we're, we're going to do is we are going to print the sum, the difference. So the difference is a three minus a two, right? And we're just going to take this value and then add it with the last value, which is a three and then we print in. Um, so if it's not an arithmetic progression, that means it's a geometric progression. So we're going to see out GP. Else see out GP, we're going to print out a new space. And then we're going to do is we're going to take the third value, right? The third value divided by the second value. So that'll give us the common ratio and then multiply by the third value to get our fourth value. So third value divided by second value. And then we're going to multiply by the third value again to get our. So this gives us our common ratio and this is going to multi, uh, give us the next value. And it's the same thing as arithmetic progression. We get the common difference, right? And then we add by the next value. And then, yeah, because they said the last value, the last, all three numbers are all zero in the end. That's why I read in the three numbers first and while they are not all equal to zero, then I do this and then I read in the three numbers again, so then by the next iteration, it would check if they are all equal to zero or not. Okay. And yeah, let's see if this works. I'm not a hundred percent sure because I did this in Java and I didn't do this in C plus plus before. So yes, uh, let's see. GCC, let's see if this works. It could be a problem with absolute value. Hope there isn't gives me a wrong answer. Okay. What, what is the problem? Um, let's see. What is the problem? Uh, a two minus a one is equal to a three minus a two. Um, let me check my Java solution real quick. It should be right. Hold up. Let me just find my previous Java solution because this, uh, a three minus a two is equal to a two minus a one. Yeah, that is right. Um, a three plus a two minus, I think that's right. Wait a three plus a two, a two minus a one. This is right. If a two minus, let's put parentheses a two minus a one is equal to a three minus a two, a three plus a three minus a two, this should be right. I mean, we could do a two minus a one. It's still the same thing because they should have a common, common number. So let's, let's try it again. But yeah, that was my solution before. So I don't know why don't know why it's not working now. Let's see. Let's see if it works now. Still wrong answer. Okay. Let's see. Let's see. Let's see. What is the problem? A three minus a two plus. Are you sure this is right? Okay. Let's, let's, let's go through this again. Four seven 10 should give us, let's print this out. Okay. Let's do this real quick. Four seven 10 AP 13. Yeah. That's right. Two six 18 GP 54. It's right. Zero zero zero. Yep. Okay. So that's really strange why my thing is not working. Five zero zero should be zero. Oh, wait, the whoops. I did not do five zero zero. Hold up. Let's see. Ah, okay. So this loop should actually be an or sign. Yeah. Yeah. So if you, I should have put a parentheses on not that. So then yeah, now it should work. So the reason why you have to put or is because if they're not all zeros, then yeah, and that's a problem, but should work now. Yeah. Now it got accepted. Okay. Yeah. So yeah, if they're not, so basically the reason why this didn't work is they have to all be zeros and then it would break. So I could have done this way while they're, let's say they're all equal to zero. Instead of putting or kind of this way, put parentheses on all of them and then put a not so while they're not all equal to zero. So this would actually distribute the, then the not equal to zero into all of these and it would give the same answer. So yeah, that's why the or you had to put an or if you're going to distribute the not to each of these. But yeah, this is basically the solution to the problem. Ray coms subscribe. I'll check you guys later. This is a pretty basic problem, but yeah, Ray coms subscribe. I'll check you guys later. Peace.