Description
The Sky is Sprite.
The Birds is a Fly in the Sky.
The wind is Wonderful.
Blew Throw the Trees
Trees is Shaking, Leaves is falling.
Lovers Walk passing, and so is you.
................................ Write in 中文版 class by Yifenfei
Girls is clever and bright. In HDU every girl like math. Every girl like to solve math problem!
Now, you have nonnegative integer A and b. Find the nonnegative integer X and integer Y to satisfy x*a + y*b = 1. If No such answer print "Sorry" instead.
Input
The input contains multiple test cases.
Each case, nonnegative integer A, b (0<a, b<=2^31)
Output
Output nonnegative integer X and integer Y, if there is more answers than the X smaller one would be choosed. If no answer put "sorry" instead.
Sample Input
77 5110 4434 79
Sample Output
2-3sorry7-3 give A1 A2 X1 x2 make A1*x1+a2*x2=1 if not present, output sorry apply extended Euclidean algorithm template note output does not need to consider the final space control note X1 to be greater than 0
#include"iostream"using namespacestd;voidgcdintAintBint&d,int&x,int&y) { if(!B) {d=a;x=1; y=0;} Else{gcd (b,a%b,d,y,x); y-=x* (A/b);}}intMain () {intM,n; while(cin>>m>>N) {intx,y,d; GCD (M,n,d,x,y); if(d!=1) cout<<"Sorry"<<Endl; Else { while(x<0) {x+=N; Y-=m; } cout<<x<<" "<<y<<Endl; } } return 0;}
Sixth week of training mathematics concepts and methods linear equation I problem of number theory