Cod sursa(job #230257)

Utilizator raduzerRadu Zernoveanu raduzer Data 13 decembrie 2008 14:18:55
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <cstdio>

const int MAX_N = 1000010;

typedef long long ll;

int n;
int a[MAX_N], b[MAX_N], c[MAX_N];
int d[MAX_N], next[MAX_N];
int x, y, z;

inline int color(int x)
{
	if (x > y) return (!d[x]) ? x : next[x];
	if (!d[x]) d[x] = z;
	return next[x] = color(next[x]);
}

int main()
{
	int i;
	freopen("curcubeu.in", "r", stdin);
	freopen("curcubeu.out", "w", stdout);
	
	scanf("%d %d %d %d", &n, a + 1, b + 1, c + 1);
	
	for (i = 2; i < n; ++i)
	{
		a[i] = ((ll)a[i - 1] * i) % n;
		b[i] = ((ll)b[i - 1] * i) % n;
		c[i] = ((ll)c[i - 1] * i) % n;
	}
		
	for (i = 1; i < n; ++i) 
		if (a[i] > b[i]) a[i] ^= b[i] ^= a[i] ^= b[i];
	
	for (i = 1; i < n; ++i)
		next[i] = i + 1;
	
	for (i = n - 1; i > 0; --i) {
		x = a[i]; y = b[i]; z = c[i];
		color(x);
	}
	
	for (i = 1; i < n; ++i)
		printf("%d\n", d[i]);
}