1.题目描述:点击打开链接
2.解题思路:本题利用暴力搜索解决。直接从1234开始枚举除数,由于乘积不能超过100000,所以上限是100000/n。然后判断得到的乘积和除数中的所有数是否都各不相同即可。
3.代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;
bool check(int m, int n)
{
bool ok = true;
int vis[10];
memset(vis, 0, sizeof(vis));
for (int i = 0; i < 5; i++)
{
vis[m % 10]++, vis[n % 10]++;
if (vis[m % 10]>1 || vis[n % 10] > 1)ok = false;
m /= 10, n /= 10;
}
return ok;
}
int main()
{
//freopen("t.txt", "r", stdin);
int n;
int rnd = 0;
while (~scanf("%d", &n) && n)
{
if (rnd++)cout << endl;
int ok = 0;
for (int divisor = 1234; divisor <= 100000/n; divisor++)
{
int m = divisor*n;
if (check(m, divisor))
{
ok = 1;
printf("%05d / %05d = %d\n", m, divisor, n);
}
}
if (!ok)
printf("There are no solutions for %d.\n", n);
}
return 0;
}