 what's up guys my name is Michael and welcome to my YouTube channel today we are going to go over another spodge problem called candy three basically you have n kids who have their all their backpack stuff with candy but then some some arguments happen teacher realizes this and then he says put all your candies into the table here then there is a large pile of candies on the table now the teacher asks I will divide these candies into n equal heaps and everyone will get one of then the kids asks is this actually possible so basically in this problem statement you are given n cans and you see if can you divide them the total candies the candies into n equal heaps okay so the test is basically there's t test cases first sign is n number of children each net n lines contains a number of candies each child bought okay so you would print out yes if the candies can be equally distributed no otherwise okay so how do you do this problem well um the problem is actually not that difficult so remember back when we talked about modular arithmetic okay so remember we talked about modular arithmetic right so like um if I do like a plus b right and I mod by c this is equivalent to a mod by c plus b mod by c right so we're going to do the same thing here basically we're going to we're going to use this exact same thing here so they're asking if um they're asking is if can I equally distribute so I have n students and each of them have has this candy right and can I equally distribute all of them into uh n so we know that uh we have to mod by n because that's uh distribute equally distribute it so this is where you have to check can the sum of all the candies be divisible by n so if I sum up all the candies let's say c is a each candy of ci right and I sum up from zero to all n students for every candy is this total sum um is this total sum divisible by n right right if I divide by n is it uh is it divisible by n right so to check if something's divisible by n you just have to check if it's mod by n if and this is equal to zero okay so that's basically all you have to do you just have to sum up all the values and check if you can mod by n so now the only issue with this is that um um summing up could get overflow so what you do is that for each value you just use mod by n and while you're summing it up so you're gonna for each value you're gonna be ci mod by n so summation of zero to n each of them you're gonna sum them up and mod by n and then take the whole thing and mod by n and check if it does a sequel to zero and that'll basically tell you the answer because uh what they're asking is is that if I all add up all the candies can I equally distribute them is it divisible by n right into n piles so that's is it divisible by n and modding by n means that you check the remainder does equal to zero okay so guys this is the code uh we're reading the number of test cases while t minus minus for each test case you're gonna read in the total number of students then you gotta create your array for every single candy I put d you could you see whatever all right uh then you need to have your sum um so then this is what I did basically I just loop through from zero to n right and then I'm gonna read in every single candy value and then while it's reading it I'm going to sum up so sum is gonna equal to the sum of the current sum plus equal to plus the candy the current candy at i then I take the whole thing and then I mod it by n and then uh it's gonna keep doing that over and over again right so that's basically just distributing the modulus by n inside of the summation and then after that if I check if sum is equal to zero then I print out yes otherwise I print out no and that's basically the whole code all right I got a seed here so yeah raycobb subscribe if this was not a hard problem I'll check you guys later peace