#include <stdio.h>
#define N 8
int a[10] = {0};
int b[10] = {0};
void func(int n)
{
if (n == 0)
{
int aa, bb;
aa = 0;
for (int i = 0; i < N / 2; ++i)aa = aa * 10 + b[i];
if (aa<1234)
{
return;
}
bb = 0;
for (int i = N / 2; i < N; ++i)bb = bb * 10 + b[i];
if (aa > bb)return;
int ab = aa * bb;
while (ab)
{
int w = ab % 10;
for (int i = 0; i < N; ++i)
if (b[i] == w)return;
ab /= 10;
}
printf("answer : %d %d = %d\n", aa
, bb
, aa
* bb
); return;
}
for (int i = 0; i < 10; ++i)
{
if (a[i] == 0)
{
a[i] = 1;
b[n - 1] = i;
func(n - 1);
a[i] = 0;
}
}
}
int main()
{
func(N);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTiA4CmludCBhWzEwXSA9IHswfTsKaW50IGJbMTBdID0gezB9Owp2b2lkIGZ1bmMoaW50IG4pCnsKICAgIGlmIChuID09IDApCiAgICB7CiAgICAgICAgaW50IGFhLCBiYjsKICAgICAgICBhYSA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOIC8gMjsgKytpKWFhID0gYWEgKiAxMCArIGJbaV07CiAgICAgICAgaWYgKGFhPDEyMzQpCiAgICAgICAgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGJiID0gMDsKICAgICAgICBmb3IgKGludCBpID0gTiAvIDI7IGkgPCBOOyArK2kpYmIgPSBiYiAqIDEwICsgYltpXTsKICAgICAgICBpZiAoYWEgPiBiYilyZXR1cm47CiAgICAgICAgaW50IGFiID0gYWEgKiBiYjsKICAgICAgICB3aGlsZSAoYWIpCiAgICAgICAgewogICAgICAgICAgICBpbnQgdyA9IGFiICUgMTA7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTjsgKytpKQogICAgICAgICAgICAgICAgaWYgKGJbaV0gPT0gdylyZXR1cm47CiAgICAgICAgICAgIGFiIC89IDEwOwogICAgICAgIH0KICAgICAgICBwcmludGYoImFuc3dlciA6ICVkICVkID0gJWRcbiIsIGFhLCBiYiwgYWEgKiBiYik7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMDsgKytpKQogICAgewogICAgICAgIGlmIChhW2ldID09IDApCiAgICAgICAgewogICAgICAgICAgICBhW2ldID0gMTsKICAgICAgICAgICAgYltuIC0gMV0gPSBpOwogICAgICAgICAgICBmdW5jKG4gLSAxKTsKICAgICAgICAgICAgYVtpXSA9IDA7CiAgICAgICAgfQogICAgfQp9CmludCBtYWluKCkKewogICAgZnVuYyhOKTsKICAgIHJldHVybiAwOwp9Cg==