do { *rmp = 0; _mdr(rmdr, rmp, n); } while (0)

void _mdr(int *rmdr, int *rmp, long long n)
{
    
    int r = n ? 1 : 0;
    while (n) { 
        r *= (n % 10);
        n /= 10; 
    }

    (*rmp)++;
    if (r >= 10)
        _mdr(rmdr, rmp, r);
    else
        *rmdr = r;
}

int main(void)
{
    int i, j, vmdr, vmp;
    const int values[] = { 123321, 7739, 893, 899998 };
    const int vsize    = sizeof(values) / sizeof(values[0]);

    
    printf();
    for (i = 0; i < vsize; ++i) {
        mdr(&vmdr, &vmp, values[i]);
        printf(, values[i], vmdr, vmp);
    }

    
    int table[10][twidth] = { 0 };
    int tfill[10]         = { 0 };
    int total             = 0;
    for (i = 0; total < 10 * twidth; ++i) {
        mdr(&vmdr, &vmp, i);
        if (tfill[vmdr] < twidth) {
            table[vmdr][tfill[vmdr]++] = i;
            total++;
        }
    }

    
    printf();
    for (i = 0; i < 10; ++i) {
        printf(, i);
        for (j = 0; j < twidth; ++j)
            printf(, table[i][j], j != twidth - 1 ?  : ); 
        printf();
    }

    return 0;
}