x是n的因子。把x枚举一下,找出最大值就行。
我开始再找a/x+b*x的最大值。当然是x=sqrt(a/b); 一直Wa 。
无奈才暴力的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
typedef long long LL;
const int maxn=1e6;
using namespace std;
int main(){
int a,b,n;
while(~scanf("%d %d %d",&a,&b,&n)){
double maxx=9999999,t;
int maxi=0;
for(int i=1;i<=n;++i){
if(n%i==0){
t=(a*1.0)/i+b*1.0*i;
if(t<maxx) maxx=t,maxi=i;
}
}
printf("%d\n",maxi);
}
return 0;
}