Cod sursa(job #465834)

Utilizator TerminatorHasta La Vista Terminator Data 25 iunie 2010 13:29:51
Problema Ratphu Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 1 Marime 0.52 kb
#include <cstdio>
#include <algorithm>

const int MAXN = 20;
using namespace std;

int n, x, cl, s, V[MAXN], i, cnt, p, a;
int main ()
{
	freopen ("ratphu.in", "r", stdin);
	freopen ("ratphu.out", "w", stdout);
	scanf ("%d%d\n", &n, &p);
	cl = n;
	while (cl)
	{
		a = cl % 10;
		V[++cnt] = a;
		cl /= 10;
	}
	sort (V + 1, V + cnt + 1);
	do {
		x = 0, s = 0;
		for (i = 1; i <= cnt; i++)
			x = x * 10 + V[i];
		if (x % p == 0)
			s = 1;
		printf ("%d %d\n", x, s);
	} while (next_permutation (V + 1, V + cnt + 1));
	return 0;
}