 What's up guys, my is Michael and welcome to my YouTube channel. So today we're going to do a contest that just came out today and I solved the first problem, but I couldn't solve the second one. So that's why I'm going to go over the first problem, because I know how to solve it. Anyway, it's CodeForce's round 629 Division 3, Divisibility Problem. Basically, all you need to know in this problem is how to use mod. How to use mod. When you take a remainder of something, A mod B is just taking the remainder of it, okay? Getting the remainder of the answer when you divide by it. That's what the mod operator is. But anyway, let's go to that deep dive into this problem. Alright, let's go it. You're given two numbers, A and B. We know that they're both positive, so that's good. Remember, both positive. Okay, in one move you could increase A by one. Your task is to find the minimum number of moves you'd have to do to make A divisible by B. If it is possible that you have zero moves, as A is already divisible by B, you have to answer T test cases. Okay, so for each test case, we're going to have A and B. So, for that case, I'm going to... First, let's write the code for that first, okay? I already did this, so bear with me. I'm going to delete the old code. So, I'm going to delete the old code real quick, but let's just go at it with a fresh slate. Okay, a fresh slate. A fresh slate, if you know what I mean. Okay, so remember, there's T test cases. So, I'm going to create a variable called T. I remember I used LL to mean a definition of long, long. So, LL just means long, long. Okay, and long, long is just a very long integer, so that I don't get overflow. Because in our test cases, you see that A and B could be 10 to the 9th, and that's a lot of zeros, and I don't want an overflow. Like in regular integer, you could only get up to 2 million, and then it starts going to negative. So, that's why we have that long, long, okay? So, what we're going to do is we're going to do CNT, and that's going to read in the value of T, the first line of the number of test cases. Then what I'm going to do is I'm going to do while T minus minus, and that's what's that going to do, is that going to read in every single each test case. Like every single each test case, okay? So, each line of test case is two integers A and B. So, I'm going to read in those. So, CN, A and B. Okay? And I've got to declare those variables also, because that'll be undefined, but yeah. CN, A and B. And what are we trying to do? We're trying to find the minimum number of moves it takes to make A divisible by B. So, I'm going to create a function, min moves, and I'm going to pass in A and B. And A and B is just going to be the regular variables A and B. This function is going to return the minimum number of moves it takes to make A divisible by B. Okay? So, I'm going to see out this function. So, I'm going to print the minimum number of moves it takes for A to become B. Okay? So now, let's write our function to make A divisible by B. Okay? So, we're going to do long, long. It's going to return an integer, which is the minimum number of moves, and call it min moves, and L, L, A, and long, long B. Okay? And those are the values that I passed in into our function, A and B. Okay? So now, let's look at a very easy case. They gave us already that it is possible that you could make zero moves if A is already divisible by B. So, let's write that. How do I check if A is already divisible by B? I mod by it. If A mod B, that means the remainder is zero. So, I take the remainder of A mod B and it's equal to zero. I just return zero. Okay? That's an easy test case. Very easy test case. Okay? So now, let's look at the other test cases. Now, I know that in order to make A divisible by B, right, they say that the moves we could make is increase A by one. Okay? So, what is the scenario where I need to make other moves to make A divisible by B? Well, I could make brute force this. And how do I do that? I would literally just have a while loop while A is not divisible by B. I'm going to increase A by one every single time. Okay? And that is going to make A divisible by B. Okay? If I increase A by one every single time to do a one move brute force A plus one every single time, I'm going to get A divisible by B. Okay? Now, there is a scenario where that, you might be wondering, hmm, well, if A is a divisible by B, right, if I'm going to increase one every single time, when will that case, when that while loop gets completed? Right? Let's say A is less than B. Right? Let's say in this test case, 123 and 456. I'm going to increase A 123 by one every single time until it is divisible by 456. And when does that occur? That will occur when our number 123 is equal to 456. So what is the minimum number of moves it takes to get 123 to 456? Easy. It's 456 minus 123. And what's 456 minus 123? 333. That's the answer. That's the minimum number of moves it takes to get A. If I keep adding A by one, I'm going to get A divisible by B in the end. Okay? And when does this happen? This happens when A is less than B. 123 is less than 456. That's why we know that if I keep increasing A by one in the end, I'm going to get A is equal to B after that condition, A is equal to B and B divided by B is divisible by B. We know B is divisible by B because that's the case of all numbers. They're divisible by itself. So 123, if I keep adding by one, when 123 is equal to 456, I know that it is divisible by each other. So that occurs when 123 is less than 456 and that's when A is less than B. So if A is less than B, all I have to do is return B minus A. Okay? That's the minimum number of moves it would take to make A divisible by B. So let's write that condition. Else if A is less than B, return B minus A. Okay? All right, now that's the case that it does. Okay? And we see it works like 123 with 456. 456 minus 123 would get us 333. And that's right. All right, let's look at the other test case. 92 and 46. Well, 92 divided by 46, it's divisible by it. If I take 92 mod 46, I'll get zero. And that's the first scenario that we wrote here already. That covers that. Now let's look at the other cases. Can I just take A mod B? Okay, what's 10 mod by 4? What is the remainder? Let's type that out. 10 mod 4. The remainder is 2. So maybe I can see the answer is 2. So there might be a test case where I could just take A mod B. Let's look at another one. 13 mod 9. 13 mod 9. Where A is 13 and B is 9. That's going to get me the remainder of 4. Well, 13 mod 9 is not 5. Their output is 5. Our output is 4. So we can't just take A mod B. There's no condition where I could just do A mod B. All right, now let's look at the other test case. 113. And 113, they got the answer 4. Well, let's think about this. Let's go back. 100 mod 13. What is that? 100 mod 13. 9. Wait a minute. 13 minus 9 is 4. So in this answer, we saw that 113 gave us the answer of 4. So if I just take 13 minus 100 mod by 13, I'm going to get the answer 4. Their exact same answer of 4. Well, 100 minus 13 minus 100, wait. 13 minus 100 mod 13. That's going to give us the answer of 4. And that's exactly the same as their output. So I know that in one test scenario, test case, what are the values of 13, 113? Well, if we figure out, go back track a little bit. 100 has the value A. A is equal to 100 in this case. B is equal to 13. So B, if I were to do B minus A mod B, that is going to be a test case, test scenario. So I'm going to do else, return B minus A mod B. Now let's think about this. The minimum number of moves it would take is to get A to be divisible by B. If A is greater than B in this case, because in our test case, A 100 is greater than 13. If I take the remainder of 113, that is the number of the remainder of 113, right? Well, I want to make 100 divisible by 13. So the remainder of 100, if I take 100 and divide by 13, the remainder, that's the number I have to the distance that is further away from our original number that we're divisible dividing by. So that's why it kind of makes sense if I would just take the one that I'm trying to make it divisible by and subtract by how far it is the remainder of it. So that's how we get this answer, B minus A mod B. And let's run this scenario and go through all the inputs. 5, 10, 4, well that gets us 2. And that's the same answer as their output. 13 and 9, what does that give us? 5, and that's the same as their output. 113, that gives us 4, and that's their output. 123, 456, gives us 333, and that's the same as their output. 92, 46, the exact same as their output, 0, 0, 0. So we got the exact same output as their answer. Let's copy and then submit this code. Give it a few seconds, maybe a minute. I don't know. The server might be slow. It's taking a while. It's taking awfully a while. Let's refresh a page. Something's up. Is the server down? Code forces server? Is it down? It's awfully strange. Maybe it's my internet connection. It's still running. Anyway, that's basically how I solved the problem. Let's just look back at... Yeah, and it got accepted. Yeah, so our answer got accepted. It just took a while to run. But yeah, that's how you would do this problem. I hope you guys enjoyed this problem, divisibility problem. I'll figure out how to do the second problem. Rate, comment, subscribe. I'll check you guys later. Peace.