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:313 pages. Algorithmic Competition Primer Classic (second edition)
#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 () {intA,b,d,x,y; while(cin>>a>>b) {gcd (a,b,d,x,y); if(d!=1) cout<<"Sorry"<<Endl; Else { while(x<0) {x+=b; Y-=A; } cout<<x<<" "<<y<<Endl; } }return 0;}
View Code
HDU 2669 Romantic