gcd与lcm计算代码

草 ,__gcd(x,y)能秒

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#includeiostream
using namespace std;
int gcd(int x,int y)
{
if(y==0) return abs(x);
return gcd(y,x%y);
}
int lcm(int x,int y)
{
if(x==0||y==0) return 0;
return abs(x*y)/gcd(x,y);
}
int main()
{
int a,b;
cin>>a>>b;
cout<gcd(a,b)<<endl;
Edited on

Give me a cup of [coffee]~( ̄▽ ̄)~*

GoodNut WeChat Pay

WeChat Pay

GoodNut Alipay

Alipay

GoodNut PayPal

PayPal