Pearls @ 2024-09-13 15:59:14
#include<bits/stdc++.h>
using namespace std;
long long s,k,a,b;
int main(){
cin>>a>>b;
if(a>b)
s=b;
else
s=a;
for(int i=1;i<=s;i++){
if(a%i==0&&b%i==0){
k=i;
}
}
cout<<k;
return 0;
}
by _chicken_ @ 2024-09-13 16:03:54
link
by _chicken_ @ 2024-09-13 16:05:02
@Pearls 1e9的数据枚举肯定会T,建议先学下正解
by huanglihuan @ 2024-09-13 16:06:10
@Pearls 直接 _gcd(a,b)
求关
by huanglihuan @ 2024-09-13 16:06:32
__gcd(a,b)
by _chicken_ @ 2024-09-13 16:08:21
@huanglihuan 有道理,但是以后遇到要求gcd且要卡常的题怎么办,系统函数未免太慢了吧
by huanglihuan @ 2024-09-13 16:09:15
@chicken 但能过。
by naoliaok_lovely @ 2024-09-13 16:10:09
@chicken 你说得对,但是 Binary gcd
by _chicken_ @ 2024-09-13 16:11:54
无所谓,我的建议是学下算法,毕竟后面还有exgcd等知识
by Pearls @ 2024-09-13 16:15:07
@huanglihuan 过了
by 幻想繁星 @ 2024-09-13 16:16:41
@chicken 事实上__gcd
不比你手写的慢