#include <iostream>
#include <cstring>
#include <cstdlib>
#include <map>


void getdigits(char buf[], int n)
{
    while (n) {
		*buf++ = n % 10;
		n /= 10;
	}
}

int compint(const void *a, const void *b)
{
	return *(const char *)a - *(const char *)b;
}

int is_vampire(char n[], const char i[], const char j[], size_t l)
{
	char k[2 * l];
	std::memcpy(k + 0, i, l);
	std::memcpy(k + l, j, l);
	std::qsort(k, 2 * l, 1, compint);
	std::qsort(n, 2 * l, 1, compint);
	return !std::memcmp(n, k, sizeof(k));
}



int main()
{
	std::map<int, std::pair<int, int> > m;

	for (int i = 100; i < 1000; i++) {
		for (int j = 100; j < 1000; j++) {
			int n = i * j;
			if (n < 100000 || n >= 1000000)
				continue;

			char ndigits[6];
			getdigits(ndigits, n);

			char idigits[3];
			char jdigits[3];
			getdigits(idigits, i);
			getdigits(jdigits, j);

			if ((i % 10 || j % 10) && is_vampire(ndigits, idigits, jdigits, 3)) {
				m[n] = std::make_pair(i, j);
			}
		}
	}


	std::cout << m.size() << " vampire numbers found:" << std::endl;

	for (std::map<int, std::pair<int, int> >::iterator it = m.begin(); it != m.end(); it++)
		std::cout << it->first << " = " << it->second.first << " * " << it->second.second << std::endl;

	return 0;
}