 What's up guys, my name is Michael and welcome to my YouTube channel. Today we are going to go over spodge EOO rectangles. Basically, you're just given n rectangles with side one and you want to count how many different rectangles can be formed with these squares and Two rectangles are different if none of them can be rotated and moved to the to obtain the second one So like if you had like this square this rectangle, right? But side two at this one right here if you were to rotate it Top like that. That's still the same Rotate it to the top like 90 degrees. We're now it's vertical It's still gonna be the same Rectangle, right? So that's why we're not we're not gonna consider that as like two different rectangles So during a rectangle construction you can neither deform the squares nor put any squares upon each other So yeah, that's basically To do this problem It's actually you have to just figure out each test case and just keep like drawing out Every single test case to see how it goes on and then you would find the pattern when you keep drawing it out But anyway, you could look at this you look at the first test case the first test case is six so we have six rectangles and You could see how many different not not six rectangles six six squares We have six squares with side one and we want to count how many rectangles there are How many different rectangles there are right? So this is there's six on this side There's six six squares and you could stack them up right next to each other for all them to the right So we have this one here two here three here four here five here six here, right? If you just stack every single Square to the right you're gonna get six different rectangles here But I also have to consider like okay Squares are technically still rectangles. So here we have If you were used to sideline two and two by two This is a this is a rectangle also, right? And then if you concatenate to another two vertical ones to the right you have this this is also a rectangle As you could see here. So yeah, the total here would be eight So if you want to do this problem, you actually have to draw it out draw draw out every single possible Every single possible thing and find the pattern. So if you were to draw out Let's say that we have the number of squares. We have is one, right? So we only have one square how many different let's just count how many different squares we could possibly make because Before you count rectangles because squares are like its own individual things squares are rectangles, right? How many different squares can we make? Okay, because once we figure out the number of squares We could figure out the number of rectangles we can make also. So let's think about it Let's say I have only one square here. Well, the different number of different squares are just going to be one, right? It's self right one square Because you only have one square and you only have itself So if n is equal to one your your answer would number of different squares is one Now let's think about two All right, let's say I have two different one by one squares Um, the number of different squares you can make is still going to be one right We're talking about squares different squares um, the reason why it's only one is because You only can make one square here like this and this is still technically the same square. So Yeah, we only we only can have a one by one square So it's still going to equal to one Now let's look at three If n is equal to three Uh, so we have three different one by one squares. Uh, how many different squares can you make? You still can only make one right number squares squares Different squares number of different squares You only still can make one because these are still technically the same square Right, they're all the same square. So it's still going to equal one Okay, now now it starts getting strange when you have four Okay, so now we have four of these tiny squares One by one squares You can make one square like this and then the second one you can make is actually a two by two square So you have two different squares actually two different squares Because you only have you have one one by one and then you have two by two And this would use up all of the different squares if you merge them together Put them together you would get this right and this would that means we have two different squares so Now let's look at um If we look at five, it's still going to be the same thing. Um, let's look at six six is going to be the same thing seven Eight is still going to be the same thing. Let's look at nine Right Now it starts getting very very very different. Okay So now when you have nine Nine different one by one squares, you realize that you could actually make three number of different squares Is actually gonna you could actually make three different squares and the reason why is is that You could actually have one square like this You could have a two by two square Like this right and you could have a three by three square See so these are three different squares if you were to make Out of nine small tiny small squares, you could make three of these So yeah, this is going to equal to three So then if you keep continue doing this the number of different squares You can possibly make is going to actually end up if you Find the patterns of one is one right Two is going to be two Out of two is going to be one Three is going to be one Four is going to be two And so on so far until you get to nine and this is going to be three So if you continue going forward you realize this is actually going to be the floor Of the square root of n Floor so rounded down when I say floor, it's rounded down. So this is going to be the square root of n and that will get get you the Number of different squares you need that are added to create squares So now let's talk about how to do rectangles because rectangles are a little bit different So remember squares are also rectangles So if we find square number of squares different squares and then add it with number of different rectangles You're going to get The answer right So now let's talk about rectangle. All right guys. So now let's think about how many different rectangles you could have counting because then If we're excluding squares We just count rectangles now Then you're gonna you'll be able to solve the problem if you just add it by the number of squares Different different squares. I mean, so let's say we have n equal one. Well If we just have one square you can't form any rectangles because we're not gonna We're excluding squares, right? So this is the number of different rectangles Different rectangles It's you can't form any it'll just be zero because This is not a using this square. You can't form a rectangle like this So in this case if n equal to one, we're going to get zero Now let's check if n equal to two. What would that give us? So you have two of these You could have a one by two One by two This is a rectangle and you also could have two by one Except this is the exact same rectangle, right because you could rotate it So that's why we only count it once so this is not going to be it So this is going to be number of rectangles Different rectangles Number of different rectangles is going to equal to only one. Okay So if n is equal to two, we only get one Okay, let's look at another one. So let's write it. Let's rewrite here. So we have one to zero Two is just going to miss one. Okay. Now if n is equal to three How many different rectangles can you have you got to have one by two and one by three and the rest would not matter because The those you could only rotate it Right, like if you do two by one, that's just the same as one by two rotate it and three by one still the same thing as three by One by three rotated. So that's why this is if four three is just going to equal the two Right. So we only have two of these Okay Um, now let's continue. Let's continue. Let's do four This is a little get this gets a little bit more interesting So in here we have Let's see. We have one by two get one by three And you have one by four and um Yeah, that's that's the only thing you have you could only form these because The rest of rectangles are just going to be the exact same thing but rotated. So yeah before it would just be three Okay, so now let's go back to original. We have one zero. We have two is going to equal two Two is going to equal two One three was going to three was a two four is three Right Okay, so now let's continue Now we have five If you have one two three four five How many different rectangles you could have you could have one by two You have one by three You could have one by four And you could have one by five Anything else you could try is probably not going to get your rectangle because It's just the same thing rotated. So you have one two three four So n equals five you only could have four rectangles Four different rectangles. Okay. So now Let's look at a final case of six So let's look at the final test case of six So if we have six different tiny Squares like this and then if you want to Look at it. We have one by two one by three one by four one by five And then one by six Okay, so that's uh, that's the different rectangles you could possibly have Um, so yeah, we would only have n equal to five at this point. Uh, not five The different rectangles would be five because the rest you could only rotate it. So after doing all the doing all these calculations Let's just rewrite it out and then see what the pattern is. So guys, I basically just redrew the whole Counted all the different length by width Of each different rectangle for the ones that we counted. So we have one we had zero two We had a one by two rectangle For three we have one by two a two by one one by three three by one And these are just the pairs you should these are pairs and they count as one rectangle But I just labeled the pairs anyway And then for four we have one by two two by one one by three three by one one by four four by one For five we have one by two two by one one by three three by one one by four four by one one by five five by one For six we have one by two two by one one one by three three by two I three by one one by four four by two one by five five by one one by six six by one Okay, so as we could see here that our ith value the length the length value Here there's one or the width the width the width by my bad The width value is actually just going to be a maximum of the square root of n the floor of square root of n And We're actually just iterating it from one to the floor of square root of n for this one, right because the square root of To six let's say the square root of six is still lower bound is going to be one, right? So that's what this with This with this representing right Now the The jth value this one is actually just i plus one and we're just multiplying it when it's Less than if the area is less than or equal to the value of n So as you could see here one times two this value two is less than or equal to five So that's why this works and then one times three three is less than or equal to five So that's where this one works one times four four is less than or equal to five That's what this one works one times five five is less than or equal to five So that's where this one works. So your j value of counting for different rectangles could just going to be i plus one So for your i is going to equal to one to four square root of n and your j is going to equal to i plus one and two While i times j is less than or equal to n. Okay, so yeah, that's pretty much how this Code is going to work and then you're going to add count one every single time when While this is this is this works this condition works So yeah, I'm going to go over the code now and and then then after this whole thing is done we you add by the number of Different squares and that's just square root of n floor square to n. So let's go over the code now All right guys, so I'm going to explain the code now. So first we're going to read an n which is the number of One by one squares and then we have a count Variables are just going to count the number of different rectangles And the number of different squares So first we're going to have our i value is going to start from one and we're going to go up to the square root of n And then we're increasing one every single time For j we're going to start from i plus one and we're going to do it while the area of i times j is less than or equal to n So if it is less than or equal to n we're going to increase j plus plus And then we're going to increase our count by one because that's the only time when this matters Right when the area is less than or equal to n then we increase count by one. Okay And then after when this whole loop is done these two loops done So this one calculates a number of different of rectangles when that's done We have to add by the number of different squares So like in the beginning I said the number of different squares is going to be the square root of n So we have to add we have to add by square root of n which is a number of different squares And then we just print out the answer. So yeah, that's basically how you do this problem. You have to actually Come up with a pattern and then try to solve it and then yeah, that's it raycom subscribe. I'll check you guys later