
/*
Solution to problem: HEXAGONAL TRAVELLER

Algorithm:
Convert cell numbers to coordinates.
Then the shortest path length is easy to determine.
The number of paths is always a number of combinations.
Simple long arithmetics is required to compute it.
*/


#include <stdio.h>


/***** ========== LONG ARITHMETICS ========== *****/

/*
LIMITS:
Cell #1000000 is 577 steps away from the center.
Then, the longest possible path is less than 1200 steps long.
The number of combinations is less then 1200 factorial.
I.e., the maximal number has less than log10(1200!) decimal digits.
log10(1200!) < 1200 . 4 < 5000

We use 10000 base for simplicity (digits 0-9999).
Therefore, the maximal number of digits is less than 5000/4 < 1500.
*/

#define MAXDIGS  2000
#define BASE  10000
#define BASESIZE  "4"

typedef struct bignum_str {
	int beg;
	int dig[MAXDIGS];   /* dig[beg] ... dig[MAXDIGS-1] form the number */
} bignum_t;

/* num = 1 */
void one (bignum_t* num)
{
	int i;
	for ( i = 0;  i < MAXDIGS;  ++i )  num->dig[i] = 0;
	num->dig[num->beg = MAXDIGS-1] = 1;
}

/* output num in decimal notation */
void print (bignum_t* num)
{
	int i, first = 1;
	for ( i = num->beg;  i < MAXDIGS;  ++i )
		if ( !first )
			printf ("%0" BASESIZE "d", num->dig[i]);
		else if ( num->dig[i] > 0 || i == MAXDIGS-1 )
		{
			printf ("%d", num->dig[i]);
			first = 0;
		}
}

/* num *= x   (x is "one digit", i.e., x < 10000) */
void mul (bignum_t* num, int x)
{
	int i, c = 0;
	for ( i = MAXDIGS;  --i >= num->beg; )
	{
		num->dig[i] = num->dig[i] * x + c;
		c = num->dig[i] / BASE;
		num->dig[i] %= BASE;
	}
	if ( c > 0 && num->beg > 0 )
		num->dig[--num->beg] = c;
}

/* num /= x   (x is "one digit", i.e., x < 10000) */
void div (bignum_t* num, int x)
{
	int i, c = 0;
	for ( i = num->beg;  i < MAXDIGS;  ++i )
	{
		num->dig[i] += c * BASE;
		c = num->dig[i] % x;
		num->dig[i] /= x;
	}
	if ( num->beg < MAXDIGS-1 && num->dig[num->beg] == 0 )
		++num->beg;
}


/***** ========== CELL COORDINATES ========== *****/

/*
Convert cell number to its coordinates:

      / \   / \   / \
     /   \ /   \ /   \
    | 10  |  3  |  4  |
    |-1,-3|-1,-1|-1,1 |
   / \   / \   / \   / \
  /   \ /   \ /   \ /   \
 |  9  |  2  |  1  |  5  |
 | 0,-4| 0,-2| 0,0 | 0,2 |
  \   / \   / \   / \   /
   \ /   \ /   \ /   \ /
    |  8  |  7  |  6  |
    | 1,-3| 1,-1| 1,1 |
     \   / \   / \   /
      \ /   \ /   \ /
*/

#define DIRS  6
int dirx[DIRS] = { 0, -1, -1,  0, +1, +1};
int diry[DIRS] = {-2, -1, +1, +2, +1, -1};
int dirc[DIRS] = { 1,  0,  1,  1,  1,  1};

void num2xy (int n, int *px, int *py)
{
	int siz, d;

	*px = 0;  *py = 0;  --n;

	for ( siz = 0;  n > 0;  ++siz )
		for ( d = 0;  d < DIRS;  ++d )
		{
			int s = siz + dirc[d];
			if ( n < s )  s = n;
			n -= s;
			*px += s * dirx[d];
			*py += s * diry[d];
		}
}


/***** ========== PROGRAM ========== *****/

int main (void)
{
	static bignum_t num;
	int i, n1, x1, y1, n2, x2, y2, x, y, d, c;

	for ( ; ; )
	{
		n1 = n2 = 0;
		scanf ("%d%d", &n1, &n2);
		if ( n1 == 0 || n2 == 0 )  break;
		num2xy (n1, &x1, &y1);
		num2xy (n2, &x2, &y2);
		x = (x1 < x2) ? x2 - x1 : x1 - x2;
		y = (y1 < y2) ? y2 - y1 : y1 - y2;

		/* shortest path */
		if ( x < y )
		{
			d = (x+y) / 2;
			c = x;
		}
		else
		{
			d = x;
			c = (x-y) / 2;
		}

		if ( c == 0 || c == d )
			printf ("There is 1"
					" route of the shortest length "
					"%d.\n", d);
		else
		{
			/* comb(d,c) = d! / c! / (d-c)! */
			printf ("There are ");
			one (&num);
			for ( i = 1;  i <= d;  ++i )
				mul (&num, i);
			for ( i = 1;  i <= c;  ++i )
				div (&num, i);
			for ( i = 1;  i <= d-c;  ++i )
				div (&num, i);
			print (&num);
			printf (" routes of the shortest length "
					"%d.\n", d);
		}
	}
	return 0;
}

