求助,30分,WA
查看原帖
求助,30分,WA
1264600
Lazy_make_name楼主2024/3/2 20:08

我的算法有亿点点暴力,没涉及到高级语句

应该你们能看懂

#include<iostream>
using namespace std;
bool huzhi(int a,int b){
	for(int i=2;i<=min(a,b);i++)
		if(a%i==0&&b%i==0)
			return 0;
	return 1;
}
int main(){
	int A,B,L,A_,B_;
	float bi,biaozhun,zuixiao=100;
	cin>>A>>B>>L;
	biaozhun=A/B;
	for(float i=1;i<=L;i++)
		for(int j=1;j<=L;j++){
			bi=i/j;
			if(bi-biaozhun>0)
				if(bi-biaozhun<zuixiao&&huzhi(i,j)){
					A_=i;
					B_=j;
					zuixiao=bi-biaozhun;
				}	
		}
	cout<<A_<<" "<<B_;
}
2024/3/2 20:08
加载中...