Problem Link:- https://mycode.prepbytes.com/problems/maths/CHERRED
My Approach:-
- let A and B be the candies given to each person than we can say that
a valid distribution will be xA+yB=c - from A=0 to A=n we will equate the above equation than find a valid B and if
(A+B<=n) than it will be a valid distribution.
My Code:-
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
//write your code here
int t ; cin>>t;
for(int i=0;i<t;i++)
{
ll count=0;
ll n,c,x,y; cin>>n>>c>>x>>y;
for(int r=0;r<=n;r++)
{
ll z=-1;
if((c-x*r)<0)
break;
if((c-x*r)%y==0)
{
z=(c-x*r)/y;
}
if(z>=0)
{
if(r+z<=n)
{
count++;
// cout<<r<<" "<<z<<endl;
}
}
}
cout<<count<<endl;
}
return 0;
}