社区讨论

关于上个帖子的解释+求助

B3736[信息与未来 2018] 最大公约数参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mi5oq9f9
此快照首次捕获于
2025/11/19 15:32
3 个月前
此快照最后确认于
2025/11/19 15:35
3 个月前
查看原帖
为了给同学展示更相减损术正确性,于是改了代码(改成了两个数),因此复制时复制错了,至于两个都是错的,这里附上评测记录 代码更正:
更相减损术
源代码
CPP
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int gcd(int a,int b){
	while(a!=b){
		if(a>b) a-=b;
		else b-=a;
	}
	return a;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>a>>b>>c;
	int x=gcd(a,b);
	cout<<gcd(x,b);
	return 0;
} 
辗转相除法
源代码
CPP
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x;
int gcd(int a,int b){
	if(b){
		return gcd(b,a%b); 
	}else{
		return a;
	}
}

int main(){
	cin>>a>>b>>c;
	x=gcd(a,b);
	cout<<gcd(x,c);
	return 0;
} 

回复

2 条回复,欢迎继续交流。

正在加载回复...