1 #include<iostream>
2 #include<cstdio>
3 #include<queue>
4 #include<cstdlib>
5 using namespace std;
6 const int MAXN=1001;
7 int vis[MAXN][MAXN];
8 int x,y,z;
9 int step=0;
10 int p1,p2;
11 void bfs()
12 {
13 queue<int>qx;queue<int>qy;
14 qx.push(x);qy.push(y);
15 while(qx.size()!=0&&qy.size()!=0)
16 {
17 int wx=qx.front();int wy=qy.front();
18 if(wx==z||wy==z)
19 {printf("%d",step/2);exit(0);}
20 qx.pop();
21 qy.pop();
22 if(wx<0||wy<0||wx>x||wy>y||vis[wx][wy]==1)continue;
23 vis[wx][wy]=1;
24 step++;
25 qx.push(x);qy.push(wy);// x灌满
26 qx.push(0);qy.push(wy);// 把x倒空
27 qx.push(wx);qy.push(y);// y灌满
28 qx.push(wx);qy.push(0);// 把y倒空
29 qx.push(0);qy.push(wy+wx);// x - > y no shenyu
30 qx.push(wx-y+wy);qy.push(y);// you shengyu
31 qx.push(wx+wy);qy.push(0);// y - > x noshengyu
32 qx.push(x);qy.push(wy-x+wx); // youshengyu...
33 }
34 }
35 int main()
36 {
37 scanf("%d%d%d",&x,&y,&z);
38 bfs();
39 printf("impossible");
40 return 0;
41 }