templete_extgcd

来源:互联网 发布:发房源软件 编辑:程序博客网 时间:2024/05/22 17:37
#include <stdio.h>#include <string.h>#include <iostream>#include <string>using namespace std;typedef long long LL;int extgcd(int a, int b, LL &d, LL &x, LL &y){if (b == 0){d = a;x = 1;y = 0;}else{extgcd(b, a % b, d, y, x);y -= x * (a / b);}}int main(){LL x, y, d;extgcd(15, 6, d, x, y);cout << "gcd(a, b) = " << d << endl;cout << "x = " << x << endl;cout << "y = " << y << endl;system("pause");return 0;}

原创粉丝点击