A teacher purchased m candies to distribute amongst the students of his class. The class has a boys and b girls. The number of candies given to a boy and girl can be different, but all the boys should get the same number of candies and similarly all the girls get the same number of candies. Since the candies are expensive, the teacher does not want any of the candies to be left after distribution. Given the number of candies m, number of boys a and number of girls b, find is it possible to distribute the candies with forestated constraints such that no candy is left in the end.
unsigned long long int x=max(a,b);
unsigned long long int p=m/x;
for(unsigned long long int i=1;i<=p;i++)
{
unsigned long long int y=p*a;
if((m-y)%b==0)
{
return "Yes";
}
}
return "No";}
Aucun commentaire:
Enregistrer un commentaire