 What's up guys, Mike the Coder here. Today we are going to go over a weird algorithm for CSES problem sets. Now you guys wanted to know, you guys wanted me to go over CSES problem sets, so I'm gonna do that. I did solve a few of them. So I did some of these. Some of them I actually had to look at the solution to see how they did it. But I'm gonna redo all the problems that I will go over again so that I could explain it better to you guys. And then once that happens, yeah, once that happens, then yeah, I'm gonna redo all these problems and then once that happens, once that happens and yeah, well I'll show you guys how to do it and then I'll give video tutorials for that. But without further ado, let's go over the first problem. Weird algorithm. This is not that difficult. So there's this algorithm where if and as even, you're gonna divide the number by two. If it's odd, you're gonna multiply it by three and then add one. And we wanna repeat this until n is one. And so the following sequence is three, 10, five, 16, eight, four, two, one. So in this case, three is odd, right? Since three is odd, we're gonna multiply it by three and then add one, so that gives us 10. And since 10 is even, we're gonna divide it by two. That gives us five. Now five is odd, so we're gonna multiply it by three and add one and that's 16. And 16 is even, we divide it by two, that gives us eight. Then eight is even, we divide it by two, we get four. Four is divided by two and then we get two. Two is even divided by two, we get one. Now when it's finally one, yeah, that's it. So now your task simulate the algorithm with a given value of n. So print the line for all the values of n during the algorithm. So yeah, this problem is just an implementation simulation. So to do that, I'll just show you guys the code because it's actually not that hard. You just have to code this up. So I did this in one go. So, see I have a number called n, I read it in. Then I say while n is greater than one, right? While it's greater than one, then I'm just gonna print it out and print out a space. So I see out n and then print out a space. And then what I'm gonna do is I check if it's even. So to do that, I mod it by two and when we have even numbers, that means that the remainder, when you mod it by two is equal to zero. So that's why the answer is if n is mod by two is equal to zero, then that means even, we're gonna just divide n divided by two. So n is gonna equal to n divided by two and that gives us an answer for that. Otherwise, if it's odd, we're just gonna take n, we're gonna multiply by three and add one. So we're gonna keep doing this until n becomes one, right, if n is greater than one, it's gonna, sooner or later, it's gonna become one. And in the end, we're just gonna print out one because at the end of this, yeah, that's the gist of it. After this ends, it's gonna be zero, right? Or less than or equal to one and then we just print out one because one is the last value. So, yeah, that's pretty much the gist of it. Yeah, that's the code. Hope you guys enjoyed this video. This video is really easy. This problem is really easy. Yeah, then, yeah, rate, comment, subscribe. I'll do the rest of these problem sets again. Yeah, peace.