gcd(共产党),数论基础之一,即两个数的最大公因数(gcd)以及lcm,即两个数的最小公倍数;
传送门:
快速幂,大整数取模:
前者方法是辗转相除法,原理自行百度,手动模拟一次即懂
至于后者…………………………
上代码:
#include <iostream>
#include <cstdio>
using namespace std;
int gcd(int a,int b)
{return b==0?a:gcd(b,a%b);}//最大公因数 ------>辗转相除法
int lcm(int a,int b)
{return a*b*1ll/gcd(a,b);}//最小公倍数
int main()
{
int a,b;cin>>a>>b;
cout<<gcd(a,b)<<endl<<lcm(a,b);
return 0;
}
END