>>934
long longを使いたくなかった。正直反省してない
#include <stdio.h>
void swap(int* x, int* y) {int temp = *x; *x = *y; *y = temp;}
void reverse(int* first, int* last) {for(; ; ) if (first == last || first == --last) return; else swap(first++, last);}
int next_permutation(int* first, int* last) {
    int* i = last - 1, *j, *k;
    if (first == last || first + 1 == last) return 0;
    for(; ; ) {
        j = i--;
        if (*i < *j) {k = last; while (!(*i < *--k)){} swap(i, k); reverse(j, last); return 1;}
        if (i == first) {reverse(first, last); return 0;}
    }
}
int main(void) {
    int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    do {
        if (a[9] == 0 && /* 10の倍数 */
        a[1] % 2 == 0 && /* 2の倍数 */
        a[5] % 2 == 0 && /* 6の倍数(1) */
        a[4] % 5 == 0 && /* 5の倍数 */
        (a[2] * 2 + a[3]) % 4 == 0 && /* 4の倍数 */
        (a[0] + a[1] + a[2]) % 3 == 0 && /* 3の倍数 */
        (a[5] * 4 + a[6] * 2 + a[7]) % 8 == 0 && /* 8の倍数 */
        (a[0] + a[1] + a[2] + a[3] + a[4] + a[5]) % 3 == 0 && /* 6の倍数(2) */
        (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8]) % 9 == 0 && /* 9の倍数 */
        (a[0] + a[1] * 5 + a[2] * 4 + a[3] * 6 + a[4] * 2 + a[5] * 3 + a[6]) % 7 == 0 /* 7の倍数 */)
            printf("%d%d%d%d%d%d%d%d%d%d\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
    } while (next_permutation(a, a + 10));
    return 0;
}