我的算法有亿点点暴力,没涉及到高级语句
应该你们能看懂
#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_;
}