Solving this equation by dophantine equation

Sir ,
let g=gcd(w,d);
my first condition is same i.e
if(p%g!=0) cout<<"-1";

After this I thought to use dophantine equation as follows:
I found x0 & y0 by extended euclid algorithm as discussed in the above course.
Now we can have infinitely many solutions therefore,
x=x0+(b/g)*t; y=y0 -(a/g)*t;
and I also know x+y+z=n
hence I can also say 0<=x+y<=n;
and simulntaneously x>=0 and y>=0 .
Now in the end I have 3 inequalities,
1)x>=0, 2)y>=0 and 3) 0<=x+y<=n;
solving these three inequalities will give me a “t” and then substituting it I can get x,y,z. I have thoroughly checked my inequalities condition and I ask whether the above method is right or wrong because I am getting wrong answer on codeforces.

Hello @ash_sinha,

It is given in the question that The numbers should meet the following conditions:

  1. x⋅w+y⋅d=p,
  2. x+y+z=n.

The Diophantine equation is very similar to the equation given in point 1.
The Diophantine equation:
x⋅w+y⋅d=GCD(w,d)
where w and d are constants and x and y are variables.

So, you can apply the above logic only if p=GCD(w,d)
Otherwise, there is no Diophantine equation given in the question.

I have responded based on my knowledge of the same.
It might not hold true.

Sir in if p!=gcd(w,d) then no answer exist , but let’s say there is an integer k such that p=k*gcd(w,d), then in that case we will solve the equation for xw+yd=gcd(w,d) and when we will find x and y values for this equation we will simply multiply the value of x and y by k,i.e. x(answer of xw+yd=p)= k * x(answer of xw +yd=gcd(w,d)) and similarly for y . thus we can apply the dophantine equation if p is a multiple of gcd(w,d)

In the first I mean to say if (p%(gcd(w,d)!=0) then no answer exist, sorry for writting wrong

Hello @ash_sinha,

It seems convincing to me.
Hey, there must be an improvement in your third equation:
3) 0<=x+y<=n
it should rather be
0<=x+y<=n-z