大数公约数
#include <iostream> #include <string> using namespace std; string s; long long gcd(long long a, long long b) { if (a % b == 0) return b; else return gcd(b, a % b); } int main() { cin >> s; long long b; cin >> b; long long a = 0;//范围问题,借助字符串 for (int i = 0; s[i] != '\0'; i++) a = (a * 10 + s[i] - '0') % b;//保证了一定比b小,long long不会溢出 cout << gcd(a, b); system("pause"); return 0; }