@Override
    public Long solve() {

        final int[] p = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
        
        permutations: do {
            long n = 0;
            for (int i = 0; i < 10; ++i) {
                n = 10 * n + p[i];
                for (long d = 3; d < 50; d += 3) {
                    if (n % d == 0) {
                        int m1 = mask(d);
                        int m2 = mask(n / d);
                        if ((m1 & m2) == 0) {
                            if (find(p, d, i + 1, m1 | m2)) {
                                break permutations;
                            }
                        }
                    }
                }
            }
        } while (previousPermutation(p));
        
        long ret = 0;
        
        for (int i = 0; i < 10; ++i) ret = ret * 10 + p[i];
        
        return ret;
    }