求助

B4025 最大公约数

mms_zx222555 @ 2024-12-30 13:11:00

#include<bits/stdc++.h>
using namespace std;
int main (){
int a,b,c;
cin>>a>>b;
if (a==b){

cout<<a;}
else {

while (a%b){
c=a%b;
a=b;
b=c;}
cout<<c;}
}

有大佬帮忙看一下吗(90) (弱弱地)


by lzXYGguanze @ 2024-12-30 13:31:48

可以用__gcd函数

#include<bits/stdc++.h>
using namespace std;
int main (){
long long a,b,c;
cin>>a>>b;
c=__gcd(a,b);
cout<<c;}
}

|