标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4400 Accepted Submission(s): 1852
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; typedef long long LL; LL extend_gcd(LL a,LL b,LL &x,LL &y){ if(!b){ x=1,y = 0; return a; }else{ LL x1,y1; LL d = extend_gcd(b,a%b,x1,y1); x = y1; y = x1 - a/b*y1; return d; } } int main() { LL a,b,x,y; while(~scanf("%lld%lld",&a,&b)){ LL d = extend_gcd(a,b,x,y); if(d!=1){ printf("sorry\n"); }else{ x = (x%b+b)%b; y = (1-a*x)/b; printf("%lld %lld\n",x,y); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5528236.html