Lickoo的小本本
Lickoo的小本本

最大公因数_最小公倍数_beta1

最大公因数_最小公倍数_beta1
typedef unsigned int uint;
using namespace std;

void Cf(uint n1,uint n2);   //辗转相除法求最大公因数
void Cm(uint n1,uint n2);   //暴力枚举求最小公倍数

int main()
{
    unsigned int Num1,Num2;
    cin >> Num1 >> Num2;
    Cf(Num1,Num2);
    Cm(Num1,Num2);
    system("pause");
    return 0;
}

void Cf(uint n1,uint n2)
{
    uint Temp;
    if(n1 == n2)
    {
        cout << n1 << endl;
        return;
    }
    else if(n1 < n2)
    {
        Temp = n1;
        n1 = n2;
        n2 = Temp;
    }
    do
    {
      Temp = n1 % n2;
      n1 = n2;
      n2 = Temp;
    }while(Temp != 0);
    cout << n1 <<endl;
}

void Cm(uint n1,uint n2)
{
    uint Temp;
    if(n1 == n2)
    {
        cout << n1 * n2 << endl;
        return;
    }
    else if(n1 < n2)
    {
        Temp = n1;
        n1 = n2;
        n2 = Temp;
    }
    if (n1 % n2 == 0)
    {
        cout << n1 << endl;
        return;
    }
    else
    {
        for(Temp = n1 * n2;Temp % n1 != 0 || Temp % n2 != 0;Temp--);
        cout << Temp << endl;
    }
}

Lickoo的小本本

最大公因数_最小公倍数_beta1
typedef unsigned int uint; using namespace std; void Cf(uint n1,uint n2); //辗转相除法求最大公因数 void Cm(uint n1,uint n2); //暴力枚举求最小公倍数 int main() { …
扫描二维码继续阅读
2022-02-26
--> <-- mouse effects show end -->