【题意】 给你一个数字n,用0~9,10个数字组成两个五位数,使得他们的商为n,按顺序输出所有结果。
【解题方法】暴力。直接枚举第二个数字,范围(1000,100000),然后判断即可。
【AC代码】
//
//Created by just_sort 2016/1/3
//Copyright (c) 2016 just_sort.All Rights Reserved
//
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include <sstream> //isstringstream
#include <iostream>
#include <algorithm>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, LL> pp;
#define REP1(i, a, b) for(int i = a; i < b; i++)
#define REP2(i, a, b) for(int i = a; i <= b; i++)
#define REP3(i, a, b) for(int i = a; i >= b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define MP(x, y) make_pair(x,y)
const int maxn = 100;
const int maxm = 2e5;
const int maxs = 10;
const int INF = 1e9;
const int UNF = -1e9;
const int mod = 1e9+7;
int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;
//head
int main()
{
int n, ks = 0;
while(scanf("%d", &n) != EOF && n){
if(ks++) printf("\n");
bool ok = 0;
//int st = clock();
REP1(i, 0, 10){
REP1(j, 0, 10){
REP1(k, 0, 10){
REP1(l, 0, 10){
REP1(m, 0, 10){
if(i != j && i != k && i != l && i != m && j != k && j != l && j != m && k != l && k != m
&& l != m){
int t1 = i * 10000 + j * 1000 + k * 100 + l * 10 + m;
if(t1 % n == 0){
int t2 = t1 / n;
int a[10], cnt = 0, b[5];
while(t2){
a[cnt++] = t2 % 10;
t2 /= 10;
}
while(cnt < 5) a[cnt++] = 0;
b[0] = a[4];
b[1] = a[3];
b[2] = a[2];
b[3] = a[1];
b[4] = a[0];
a[cnt++] = i, a[cnt++] = j, a[cnt++] = k, a[cnt++] = l, a[cnt++] = m;
sort(a, a + 10);
bool flag = true;
REP1(ii , 0, 9){
if(a[ii] == a[ii + 1]){
flag = false;
}
}
if(flag){
ok = 1;
printf("%d%d%d%d%d", i, j, k, l, m);
printf(" / ");
printf("%d%d%d%d%d", b[0], b[1], b[2], b[3], b[4]);
printf(" = %d\n", n);
}
}
}
}
}
}
}
}
if(ok == 0){
printf("There are no solutions for %d.\n", n);
}
//int en = clock();
//cout << en - st << endl;
}
return 0;
}