GCD
1 手写
int gcd(int a,int b){
return (b==0)?a:gcd(b,a%b);
}
2 编译器写(推荐)
__gcd();
LCM
long long lcm(long long a,long long b)
{
return a*b/__gcd(a,b);
}
LCPF(Least common prime factor)
ll lpf(ll a,ll b)
{
if(a<b)swap(a,b);
for(int i=2;i<=b;++i)
{
if(a%i==0&&b%i==0)return i;
}
return 1;
}