Cod sursa(job #956476)

Utilizator burakbugrulBurak Bugrul burakbugrul Data 3 iunie 2013 11:05:35
Problema NumMst Scor 23
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

#define pb push_back

using namespace std;

const int BOMB=135000;

int N,A,B,res;

vector<int> vec;

void dfs( int pl , int a , int b ){
	
	if( clock()>BOMB ){
		printf("%d %d\n",A,B);
		exit(0);
	}
	
	if( pl==(int)vec.size()-1 ){
		if( res<a*b ){
			res=a*b;
			A=a;
			B=b;
		}
		return;
	}
	
	dfs(pl+1,a+vec[pl+1],b);
	dfs(pl+1,a,b+vec[pl+1]);
}

int main(){
	
	freopen("nummst.in","r",stdin);
	freopen("nummst.out","w",stdout);
	
	scanf(" %d",&N);
	
	for( int i=2 ; i<N ; i++ )
		if( N%i==0 ){
			for( int j=1 ; j<=i ; j++ )
				vec.pb(N/i);
			break;
		}
	
	dfs(0,vec[0],0);
	
	printf("%d %d\n",A,B);
	return 0;
}