#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
int n, t, abcde;
int fghij;
int vis[10],s[6],s1[6];
bool solve(int abcde, int fghij)
{
memset(vis, 0, sizeof(vis));
int cnt1 = 5, cnt2 = 5;
memset(s, 0, sizeof(s));
memset(s1, 0, sizeof(s1));
while (abcde != 0)
{
s[cnt1] = abcde % 10;
abcde /= 10;
if (s[cnt1] == 0)
{
cnt1--;//0可以重复
continue;
}
if (vis[s[cnt1]] == 0)
vis[s[cnt1]]++;
else//有重复说明不符合
return false;
cnt1--;
}
while (fghij!=0)
{
s1[cnt2] = fghij % 10;
fghij /= 10;
if (s1[cnt2] == 0)
{
cnt2--;
continue;
}
if (vis[s1[cnt2]] == 0)
vis[s1[cnt2]] ++;
else
return false;
cnt2--;
}//同理
return true;
}
void load(int* s, int* s1)
{
for (int i = 1; i <= 5; i++)
{
cout << s[i];
}
cout << '/';
for (int i = 1; i <= 5; i++)
{
cout << s1[i];
}
cout << '=' << n;
}
int main()
{
cin >> n;
while (n != 0)
{
memset(vis, 0, sizeof(vis));
for (fghij = 1; fghij <= 98765; fghij++)
{
abcde = fghij * n;
if (abcde > 98765)
break;//超过
if (solve(abcde, fghij))
{
load(s, s1);
cout << endl;
}
}
cout << endl;//每做完一个n都要换行
cin >> n;
}
return 0;
}
直接枚举abcde,然后分解abcde和fghij即可,注意0可以重复,满足就输出。