Romantic
Title link: HDU - 2669title meaning: find a solution of a*x+b*y=1 where x is the smallest non-negative number; no solution output sorry;
#include <iostream> #include <algorithm> #include <stdio.h> using namespace std; long long exgcd(long long a, long long b, long long &x, long long &y){ if(b==0){ x=1, y=0; return a; } long long r=exgcd(b, a%b, x, y); long long t=x; x=y; y=ta/b*y; return r; } int main(){ long long a, b, x, y; while(cin >> a >> b){ if(exgcd(a, b, x, y)==1){ if(x<0) x+=b, y-=a;//x is a non-negative number, the smallest; cout << x << ' ' << y << endl; } else cout << "sorry\n"; } return 0; }