Cod sursa(job #465295)

Utilizator wefgefAndrei Grigorean wefgef Data 23 iunie 2010 19:30:08
Problema Ratphu Scor Ascuns
Compilator cpp Status done
Runda Marime 0.61 kb
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char s[20];
int n, k;
int v[20];

int main() {
    assert(freopen("ratphu.in", "r", stdin) != NULL);
    assert(freopen("ratphu.out", "w", stdout) != NULL);

    assert(scanf("%s %d", s, &k) == 2);

    n = strlen(s);
    for (int i = 0; i < n; ++i)
        v[i] = i;

    int sol = 0;
    do {
        long long number = 0;
        for (int i = 0; i < n; ++i)
            number = number * 10 + s[v[i]] - '0';
        if (number % k == 0)
            ++sol;
    } while (next_permutation(v, v + n));
    printf("%d\n", sol);
}