Problem B. Beer Refrigerator

时间:2024-09-14 22:05:50

http://codeforces.com/gym/241680/problem/B
比赛的时候考虑的是,它们3个尽可能接近,然后好麻烦,不如暴力枚举,这里不需要质因数分解,而是两重循环枚举所有因数,第3个因数也就随之确定

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int x;
int a[];
int cnt;
int k;
int ans=inf;
int ANS[];
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
freopen("beer.in","r",stdin);
freopen("beer.out","w",stdout);
in(x);
For(i,,x)
if(x%i==)
a[++cnt]=i;
For(i,,cnt)
For(j,,cnt){
k=x/a[i]/a[j];
if(x!=a[i]*a[j]*k)
continue;
if(ans>a[i]*a[j]+a[i]*k+a[j]*k){
ans=a[i]*a[j]+a[i]*k+a[j]*k;
ANS[]=a[i];
ANS[]=a[j];
ANS[]=k;
}
}
o(ANS[]);p(' ');
o(ANS[]);p(' ');
o(ANS[]);
return ;
}