Cod sursa(job #25498)

Utilizator webspiderDumitru Bogdan webspider Data 4 martie 2007 12:45:18
Problema Puteri Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasa a 10-a Marime 1.42 kb
#include <iostream>
#include <stdio.h>

using namespace std;

int nprm[] = {   2, 	 3, 	 5, 	 7,  	11, 	13, 	17, 	19, 	23, 	29,
	        31, 	37, 	41, 	43, 	47, 	53,	59, 	61, 	67, 	71,
		73, 	79, 	83, 	89, 	97,    101,    103,    107,    109,    113,
	       127 };


int pos[129][65][65][65];


int pus[129];

int n;
int i,j,k;
int npos, npc;

int pos1( int i )
{
	int x = 0;
	int a,b,c,a1,b1,c1;
	
	for ( a = 0; a < min(i,64); a++ )
	for ( b = 0; b < min(i,64); b++ )
	for ( c = 0; c < min(i,64); c++ )
	if ( pos[i][a][b][c] )
		{
			a1 = (i - a)%i;
			b1 = (i - b)%i;
			c1 = (i - c)%i;
			if ( a1 <= 64 && b1 <= 64 && c1<=64 )
			if ( pos[ i ][ a1 ][ b1 ][ c1 ] )
			{
				if ( a1 == a && b1 == b && c1 == c )
					x += pos[i][a][b][c]*(pos[i][a][b][c] - 1 );
				else
					x += pos[i][a][b][c]*pos[i][a1][b1][c1];
			}
		}
	return x/2;
}
	       
void back( int k, int lung, int pc, int last )
{
	int i;
	if ( k > 1 )
	{
	if ( (k-1) % 2 == 0 )
		npos -= pos1(pc);
	else
		npos += pos1(pc);
	}
	if ( k <= lung )
	{
		for ( i = last+1; i <= 30; i++ )
		{
			if ( pc*nprm[i] <= 128 )
				back( k+1, lung, pc*nprm[i], i);
		}
	}
}
				
		

int main()
{
	int a,b,c;
	freopen("puteri.in","r",stdin);
	freopen("puteri.out","w",stdout);

	scanf("%d\n", &n);

	for ( i = 1; i <= n; i++ )
	{
		scanf("%d %d %d\n", &a, &b, &c);
		for ( j = 2; j <= 128; j++ )
			pos[j][ a%j ][ b%j ][ c%j ]++;
	}
	back(1,4,1,-1);
		

	printf("%d\n", npos);

	return 0;
}