#include <stdio.h>
void getdigits(char buf[], int n)
{
while (n) {
*buf++ = n % 10;
n /= 10;
}
}
int is_vampire(const char n[4], const char i[2], const char j[2])
{
/* maybe a bit faster if unrolled manually */
if (i[0] == n[0]
&& i[1] == n[1]
&& j[0] == n[2]
&& j[1] == n[3])
return 1;
if (i[0] == n[0]
&& i[1] == n[1]
&& j[0] == n[3]
&& j[1] == n[2])
return 1;
if (i[0] == n[0]
&& i[1] == n[2]
&& j[0] == n[1]
&& j[1] == n[3])
return 1;
if (i[0] == n[0]
&& i[1] == n[2]
&& j[0] == n[3]
&& j[1] == n[1])
return 1;
if (i[0] == n[0]
&& i[1] == n[3]
&& j[0] == n[1]
&& j[1] == n[2])
return 1;
if (i[0] == n[0]
&& i[1] == n[3]
&& j[0] == n[2]
&& j[1] == n[1])
return 1;
if (i[0] == n[1]
&& i[1] == n[0]
&& j[0] == n[2]
&& j[1] == n[3])
return 1;
if (i[0] == n[1]
&& i[1] == n[0]
&& j[0] == n[3]
&& j[1] == n[2])
return 1;
if (i[0] == n[1]
&& i[1] == n[2]
&& j[0] == n[0]
&& j[1] == n[3])
return 1;
if (i[0] == n[1]
&& i[1] == n[2]
&& j[0] == n[3]
&& j[1] == n[0])
return 1;
if (i[0] == n[1]
&& i[1] == n[3]
&& j[0] == n[0]
&& j[1] == n[2])
return 1;
if (i[0] == n[1]
&& i[1] == n[3]
&& j[0] == n[2]
&& j[1] == n[0])
return 1;
if (i[0] == n[2]
&& i[1] == n[0]
&& j[0] == n[1]
&& j[1] == n[3])
return 1;
if (i[0] == n[2]
&& i[1] == n[0]
&& j[0] == n[3]
&& j[1] == n[1])
return 1;
if (i[0] == n[2]
&& i[1] == n[1]
&& j[0] == n[0]
&& j[1] == n[3])
return 1;
if (i[0] == n[2]
&& i[1] == n[1]
&& j[0] == n[3]
&& j[1] == n[0])
return 1;
if (i[0] == n[2]
&& i[1] == n[3]
&& j[0] == n[0]
&& j[1] == n[1])
return 1;
if (i[0] == n[2]
&& i[1] == n[3]
&& j[0] == n[1]
&& j[1] == n[0])
return 1;
if (i[0] == n[3]
&& i[1] == n[0]
&& j[0] == n[1]
&& j[1] == n[2])
return 1;
if (i[0] == n[3]
&& i[1] == n[0]
&& j[0] == n[2]
&& j[1] == n[1])
return 1;
if (i[0] == n[3]
&& i[1] == n[1]
&& j[0] == n[0]
&& j[1] == n[2])
return 1;
if (i[0] == n[3]
&& i[1] == n[1]
&& j[0] == n[2]
&& j[1] == n[0])
return 1;
if (i[0] == n[3]
&& i[1] == n[2]
&& j[0] == n[0]
&& j[1] == n[1])
return 1;
if (i[0] == n[3]
&& i[1] == n[2]
&& j[0] == n[1]
&& j[1] == n[0])
return 1;
return 0;
}
int main()
{
for (int i = 10; i < 100; i++) {
for (int j = 10; j < 100; j++) {
int n = i * j;
if (n < 1000)
continue;
char ndigits[4];
getdigits(ndigits, n);
char idigits[2];
char jdigits[2];
getdigits(idigits, i);
getdigits(jdigits, j);
if (is_vampire(ndigits, idigits, jdigits))
printf("%d * %d = %d\n", i
, j
, n
); }
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGdldGRpZ2l0cyhjaGFyIGJ1ZltdLCBpbnQgbikKewogICAgd2hpbGUgKG4pIHsKCQkqYnVmKysgPSBuICUgMTA7CgkJbiAvPSAxMDsKCX0KfQoKaW50IGlzX3ZhbXBpcmUoY29uc3QgY2hhciBuWzRdLCBjb25zdCBjaGFyIGlbMl0sIGNvbnN0IGNoYXIgalsyXSkKewogICAgCS8qIG1heWJlIGEgYml0IGZhc3RlciBpZiB1bnJvbGxlZCBtYW51YWxseSAqLwogICAgCWlmIChpWzBdID09IG5bMF0KICAgIAkgJiYgaVsxXSA9PSBuWzFdCiAgICAJICYmIGpbMF0gPT0gblsyXQogICAgCSAmJiBqWzFdID09IG5bM10pCgkJICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblswXQogICAgICAgICAmJiBpWzFdID09IG5bMV0KICAgICAgICAgJiYgalswXSA9PSBuWzNdCiAgICAgICAgICYmIGpbMV0gPT0gblsyXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzBdCiAgICAgICAgICYmIGlbMV0gPT0gblsyXQogICAgICAgICAmJiBqWzBdID09IG5bMV0KICAgICAgICAgJiYgalsxXSA9PSBuWzNdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bMF0KICAgICAgICAgJiYgaVsxXSA9PSBuWzJdCiAgICAgICAgICYmIGpbMF0gPT0gblszXQogICAgICAgICAmJiBqWzFdID09IG5bMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblswXQogICAgICAgICAmJiBpWzFdID09IG5bM10KICAgICAgICAgJiYgalswXSA9PSBuWzFdCiAgICAgICAgICYmIGpbMV0gPT0gblsyXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzBdCiAgICAgICAgICYmIGlbMV0gPT0gblszXQogICAgICAgICAmJiBqWzBdID09IG5bMl0KICAgICAgICAgJiYgalsxXSA9PSBuWzFdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgoKICAgICAgICBpZiAoaVswXSA9PSBuWzFdCiAgICAgICAgICYmIGlbMV0gPT0gblswXQogICAgICAgICAmJiBqWzBdID09IG5bMl0KICAgICAgICAgJiYgalsxXSA9PSBuWzNdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bMV0KICAgICAgICAgJiYgaVsxXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMF0gPT0gblszXQogICAgICAgICAmJiBqWzFdID09IG5bMl0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblsxXQogICAgICAgICAmJiBpWzFdID09IG5bMl0KICAgICAgICAgJiYgalswXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMV0gPT0gblszXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzFdCiAgICAgICAgICYmIGlbMV0gPT0gblsyXQogICAgICAgICAmJiBqWzBdID09IG5bM10KICAgICAgICAgJiYgalsxXSA9PSBuWzBdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bMV0KICAgICAgICAgJiYgaVsxXSA9PSBuWzNdCiAgICAgICAgICYmIGpbMF0gPT0gblswXQogICAgICAgICAmJiBqWzFdID09IG5bMl0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblsxXQogICAgICAgICAmJiBpWzFdID09IG5bM10KICAgICAgICAgJiYgalswXSA9PSBuWzJdCiAgICAgICAgICYmIGpbMV0gPT0gblswXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzJdCiAgICAgICAgICYmIGlbMV0gPT0gblswXQogICAgICAgICAmJiBqWzBdID09IG5bMV0KICAgICAgICAgJiYgalsxXSA9PSBuWzNdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bMl0KICAgICAgICAgJiYgaVsxXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMF0gPT0gblszXQogICAgICAgICAmJiBqWzFdID09IG5bMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblsyXQogICAgICAgICAmJiBpWzFdID09IG5bMV0KICAgICAgICAgJiYgalswXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMV0gPT0gblszXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzJdCiAgICAgICAgICYmIGlbMV0gPT0gblsxXQogICAgICAgICAmJiBqWzBdID09IG5bM10KICAgICAgICAgJiYgalsxXSA9PSBuWzBdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bMl0KICAgICAgICAgJiYgaVsxXSA9PSBuWzNdCiAgICAgICAgICYmIGpbMF0gPT0gblswXQogICAgICAgICAmJiBqWzFdID09IG5bMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblsyXQogICAgICAgICAmJiBpWzFdID09IG5bM10KICAgICAgICAgJiYgalswXSA9PSBuWzFdCiAgICAgICAgICYmIGpbMV0gPT0gblswXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzNdCiAgICAgICAgICYmIGlbMV0gPT0gblswXQogICAgICAgICAmJiBqWzBdID09IG5bMV0KICAgICAgICAgJiYgalsxXSA9PSBuWzJdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bM10KICAgICAgICAgJiYgaVsxXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMF0gPT0gblsyXQogICAgICAgICAmJiBqWzFdID09IG5bMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblszXQogICAgICAgICAmJiBpWzFdID09IG5bMV0KICAgICAgICAgJiYgalswXSA9PSBuWzBdCiAgICAgICAgICYmIGpbMV0gPT0gblsyXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKICAgICAgICBpZiAoaVswXSA9PSBuWzNdCiAgICAgICAgICYmIGlbMV0gPT0gblsxXQogICAgICAgICAmJiBqWzBdID09IG5bMl0KICAgICAgICAgJiYgalsxXSA9PSBuWzBdKQogICAgICAgICAgICAgICAgcmV0dXJuIDE7CgogICAgICAgIGlmIChpWzBdID09IG5bM10KICAgICAgICAgJiYgaVsxXSA9PSBuWzJdCiAgICAgICAgICYmIGpbMF0gPT0gblswXQogICAgICAgICAmJiBqWzFdID09IG5bMV0pCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgaWYgKGlbMF0gPT0gblszXQogICAgICAgICAmJiBpWzFdID09IG5bMl0KICAgICAgICAgJiYgalswXSA9PSBuWzFdCiAgICAgICAgICYmIGpbMV0gPT0gblswXSkKICAgICAgICAgICAgICAgIHJldHVybiAxOwoKCXJldHVybiAwOwp9CgppbnQgbWFpbigpCnsKCWZvciAoaW50IGkgPSAxMDsgaSA8IDEwMDsgaSsrKSB7CgkJZm9yIChpbnQgaiA9IDEwOyBqIDwgMTAwOyBqKyspIHsKCQkJaW50IG4gPSBpICogajsKCQkJaWYgKG4gPCAxMDAwKQoJCQkJY29udGludWU7CgoJCQljaGFyIG5kaWdpdHNbNF07CgkJCWdldGRpZ2l0cyhuZGlnaXRzLCBuKTsKCgkJCWNoYXIgaWRpZ2l0c1syXTsKCQkJY2hhciBqZGlnaXRzWzJdOwoJCQlnZXRkaWdpdHMoaWRpZ2l0cywgaSk7CgkJCWdldGRpZ2l0cyhqZGlnaXRzLCBqKTsKCgkJCWlmIChpc192YW1waXJlKG5kaWdpdHMsIGlkaWdpdHMsIGpkaWdpdHMpKQoJCQkJcHJpbnRmKCIlZCAqICVkID0gJWRcbiIsIGksIGosIG4pOwoJCX0KCX0KCglyZXR1cm4gMDsKfQo=