1 #include
2 #include
3 #include <set>
4 #include <string.h>
5 #include
6 #include
7 #include
8 using namespace std;
9 bool cmp(int a,int b){
10 return a>b;
11 }
12 const int maxn = 411;
13 int n,p,k,maxk=-1;
14 int vis[maxn]={0};
15 vector<int> res,tmp;
16 void dfs(int index,int ksum,int cntk,int nsum){
17 //if(index<1 || nsum>n || cntk>k) return;
18 if(nsum==n && cntk == k){
19 if(ksum>maxk){
20 res=tmp;
21 maxk=ksum;
22 }
23 return;
24 }
25 tmp.push_back(index);
26 if(nsum+vis[index]<=n && cntk+1<=k)dfs(index,ksum+index,cntk+1,nsum+vis[index]);
27 tmp.pop_back();
28 if(index-1>0)dfs(index-1,ksum,cntk,nsum);
29 }
30 int main(){
31 scanf("%d %d %d",&n,&k,&p);
32 int i;
33 for(i=1;i<=n;i++){
34 int res = pow(i,p);
35 if(res>n)break;
36 vis[i]=res;
37 }
38 i--;
39 dfs(i,0,0,0);
40 if(maxk==-1)printf("Impossible");
41 else{
42 printf("%d = ",n);
43 sort(res.begin(),res.end(),cmp);
44 for(int j=0;j){
45 printf("%d^%d",res[j],p);
46 if(j1)printf(" + ");
47 }
48 }
49 }