#include #include using namespace std;// 比较两个大数字符串 a 和 b,返回 true 如果 a >= b,否则 falsebool isGreaterOrEqual(const string &a, const string &b) { if (a.length() > b.length()) return true; if (a.length() < b.length()) return false; return a >= b;}// 大数减法,假设 a >= b,将字符串 a 减去 b,返回结果string subtractStrings(string a, const string &b) { int carry = 0; for (int i = 0; i < b.length(); i++) { int ai = a[a.length() - 1 - i] - '0'; int bi = b[b.length() - 1 - i] - '0'; int diff = ai - bi - carry; if (diff < 0) { diff += 10; carry = 1; } else { carry = 0; } a[a.length() - 1 - i] = diff + '0'; } for (int i = b.length(); i < a.length(); i++) { int ai = a[a.length() - 1 - i] - '0'; if (ai == 0 && carry == 1) { a[a.length() - 1 - i] = '9'; } else { a[a.length() - 1 - i] = (ai - carry) + '0'; carry = 0; } } // 去除前导零 while (a.length() > 1 && a[0] == '0') { a.erase(a.begin()); } return a;}// 大数取模函数:将大数字符串 a 对大数字符串 b 取模string modStrings(string a, const string &b) { while (isGreaterOrEqual(a, b)) { a = subtractStrings(a, b); } return a;}// 大数 GCD 函数,使用字符串实现的欧几里得算法string gcdLarge(string a, string b) { while (b != "0") { string temp = modStrings(a, b); a = b; b = temp; } return a;}int main() { string a, b; cin >> a >> b; cout << gcdLarge(a, b) << endl; // 输出大数 GCD return 0;}