递归里的求两个数的最大公因数和Ackerman函数的问题

    科技2024-10-15  21

    #include<iostream> using namespace std; int gcd(int n,int m) { if (n < m) { int temp = m; m = n; n = temp; } return m == 0 ? n : gcd(m, n % m); } int akm(int m, int n) { if (m == 0) return n + 1; else return n == 0 ? akm(m - 1, 1) : akm(m - 1, akm(m, n - 1)); } int main() { int m, n; /*cout << "求两个数的最大公因数" << endl; cout << "请输入两个数" << endl; cin >> m >> n; cout << gcd(m, n);*/ cout << "akm(m,n)的递归算法" << endl; cout << "请输入两个数" << endl; cin >> m >> n; cout << akm(m, n); return 0; }
    Processed: 0.010, SQL: 8