virtual hust 2013.6.21 NEFU 挑战编程----数论 C - Euclid Problem
思路:裸的扩展欧几里得
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> 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; } else { long long ans=exgcd(b,a%b,x,y); long long t=x; x=y; y=t-a/b*y; return ans; } } long long gcd(long long a,long long b) { if(b==0) return a; return gcd(b,a%b); } int main() { long long a,b,x,y,d; while(scanf("%lld%lld",&a,&b)!=EOF) { d=gcd(a,b); a/=d,b/=d; exgcd(a,b,x,y); cout<<x<<" "<<y<<" "<<d<<endl; } return 0; }