#include #include #include char dices[210][6]; #define FOR(i) for (a[i] = a[i-1]+1; a[i] < 10; a[i]++) void init() { char a[6]; int k = 0; for (a[0] = 0; a[0] < 10; a[0]++) { FOR(1) { FOR(2) { FOR(3) { FOR(4) { FOR(5) { memcpy(dices[k], a, sizeof(a)); k++; } } } } } } assert(k == 210); } int matches(char c, char dic[]) { for (int i = 0; i < 6; i++) { if (c == dic[i] || ((c == 6 || c== 9) && (dic[i] == 6 || dic[i] == 9))) return 1; } return 0; } int ok(int x, int y) { const char sqrs[9][2] = { {0, 1}, {0, 4}, {0, 9}, {1, 6}, {2, 5}, {3, 6}, {4, 9}, {6, 4}, {8, 1} }; for (int i = 0; i < 9; i++) { if (matches(sqrs[i][0], dices[x]) && matches(sqrs[i][1], dices[y])) continue; if (matches(sqrs[i][0], dices[y]) && matches(sqrs[i][1], dices[x])) continue; return 0; } return 1; } int main() { int count = 0; init(); for (int i = 0; i < 210; i++) { for (int j = i+1; j < 210; j++) { if (ok(i, j)) count++; } } printf("%d\n", count); }