-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path+veSolOfax+by=d.cpp
More file actions
43 lines (40 loc) · 864 Bytes
/
+veSolOfax+by=d.cpp
File metadata and controls
43 lines (40 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll g, x, y;
void extendedEuclid(ll A,ll B) {
if(B == 0) {
g = A;
x = 1;
y = 0;
}
else {
extendedEuclid(B, A%B);
ll temp = x;
x = y;
y = temp - (A/B)*y;
}
}
int main()
{ //number of nonnegative solution of ax+by=d
int q;
cin>>q;
while(q--)
{
ll a,b,d,e=0;
cin>>a>>b>>d;
extendedEuclid(a,b);
if(d%g !=0){
cout<<"0\n";
continue;
}
//cout<<x<<" "<<y<<endl;
ll k1=ceil(-x*(d*1.0)/b);
ll k2=floor(y*(d*1.0)/a);
if(k1<=k2)
cout<<k2-k1+1<<"\n";
else
cout<<"0\n";
}
return 0;
}