P2118查错
查看原帖
P2118查错
774271
yeyixuan楼主2024/10/1 16:05
#include<bits/stdc++.h>
using namespace std;
int n,m,l,ans1,ans2;
double now,acc,cnt=0x3f3f;
int main(){
	cin>>n>>m>>l;
	acc=(n*1.0)/(m*1.0);
	for(int i=1;i<=l;i++){
		for(int j=1;j<=l;j++){
			if(__gcd(i,j)!=1) break;
			now=(i*1.0)/(j*1.0);
			if(now<acc) break;
			else {
				if(now-acc<cnt){
					ans1=i,ans2=j;
					cnt=now-acc;
				} 
			}
		}
	}
	cout<<ans1<<" "<<ans2;
	return 0;
}

求找错

2024/10/1 16:05
加载中...