[ create a new paste ] login | about

Link: http://codepad.org/FBzE5RKb    [ raw code | output | fork ]

C++, pasted on May 3:
#include <iostream>
#include <cstring>
using namespace std;
int vis[10];
int bk[10];
int check(int x, int y) {
do {
if(vis[x % 10] == 0) {
return 0;
}
vis[x % 10]--;
} while(x /= 10);
do {
if(vis[y % 10] == 0) {
return 0;
}
vis[y % 10]--;
} while(y /= 10);
return 1;
}
int check4(int x) { 
do {
if(vis[x % 10] != 0) { 
return 0;
}
vis[x % 10]++;
} while(x /= 10);
return 1;
}
int main(void) {
int cnt = 0; 
for(int i = 1023; i <= 9876; i++) {
memset(vis, 0, sizeof(vis));
if(!check4(i)) {
continue;
}
memcpy(bk, vis, sizeof(bk));
for(int j = 1; j <= 98; j++) {
memcpy(vis, bk, sizeof(bk));
if(i % j != 0) {
continue;
}

int k = i / j;
if(j > k) {
continue;
}
if(!check(j, k)) {
continue;
}
cout << j << " * " << k << " = " << i << endl;
cnt++;
}
}
cout << cnt << endl;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
6 * 201 = 1206
6 * 210 = 1260
21 * 60 = 1260
15 * 93 = 1395
35 * 41 = 1435
3 * 501 = 1503
3 * 510 = 1530
30 * 51 = 1530
21 * 87 = 1827
27 * 81 = 2187
9 * 351 = 3159
8 * 473 = 3784
12


Create a new paste based on this one


Comments: