#include <iostream>
using namespace std;
struct Table
{
int digit2;
int digit10;
int prev;
int n;
};
int main() {
int usedtable[10000];
Table table[10000];
int i;
int target = 2439;
int now, end;
for(i = 0 ; i < 10000 ; i++)
{
usedtable[i] = 0;
}
now = 0; end = 1;
table[0].n = 0;
while(end > now)
{
for(i = 0 ; i < 10 ; i++)
{
if((table[now].n + target * i) % 10 < 2)
{
int nextnum = (table[now].n + target * i);
if(nextnum == 1)
{
int n = now;
cout << target << " *" << endl;
cout << 0;
while(n)
{
cout << table[n].digit10;
n = table[n].prev;
}
cout << " =" << endl;
n = now;
cout << 1;
while(n)
{
cout << table[n].digit2;
n = table[n].prev;
}
cout<<endl;
}
if(usedtable[nextnum / 10]) continue;
usedtable[nextnum / 10] = 1;
table[end].n = nextnum / 10;
table[end].digit2 = nextnum % 10;
table[end].digit10 = i;
table[end].prev = now;
end++;
}
}
now++;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IFRhYmxlCnsKCWludCBkaWdpdDI7CglpbnQgZGlnaXQxMDsKCWludCBwcmV2OwoJaW50IG47Cn07CmludCBtYWluKCkgewoJaW50IHVzZWR0YWJsZVsxMDAwMF07CglUYWJsZSB0YWJsZVsxMDAwMF07CglpbnQgaTsKCWludCB0YXJnZXQgPSAyNDM5OwoJaW50IG5vdywgZW5kOwoJZm9yKGkgPSAwIDsgaSA8IDEwMDAwIDsgaSsrKQoJewoJCXVzZWR0YWJsZVtpXSA9IDA7Cgl9Cglub3cgPSAwOyBlbmQgPSAxOwoJdGFibGVbMF0ubiA9IDA7Cgl3aGlsZShlbmQgPiBub3cpCgl7CgkJZm9yKGkgPSAwIDsgaSA8IDEwIDsgaSsrKQoJCXsKCQkJaWYoKHRhYmxlW25vd10ubiArIHRhcmdldCAqIGkpICUgMTAgPCAyKQoJCQl7CgkJCQlpbnQgbmV4dG51bSA9ICh0YWJsZVtub3ddLm4gKyB0YXJnZXQgKiB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