Cod sursa(job #230249)

Utilizator raduzerRadu Zernoveanu raduzer Data 13 decembrie 2008 13:55:21
Problema Curcubeu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 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 color(int x, int y, int c)
{
	if (x > y) return next[x];
	if (!d[x]) d[x] = c;
	return next[x] = color(next[x], y, c);
}

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;
		
		if (a[i] > b[i]) a[i] ^= b[i] ^= a[i] ^= b[i];
	}
	
	for (i = 1; i < n; ++i)
		next[i] = i + 1;
	next[n] = n;
	
	for (i = n - 1; i > 0; --i)
		color(a[i], b[i], c[i]);
	
	for (i = 1; i < n; ++i)
		printf("%d\n", d[i]);
}