Cod sursa(job #112520)

Utilizator webspiderDumitru Bogdan webspider Data 5 decembrie 2007 20:21:55
Problema Puteri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.83 kb
#include <iostream>
#include <stdio.h>

using namespace std;

char 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 };


long long pos[65][65][65];
char ab[100001][3];

int n;
long long npos;

inline long long pos1( int i )
{
	long long x = 0;
	short a,b,c,a1,b1,c1;
	int j;
	
	bzero( pos, sizeof( pos ) );
	for ( j = 1; j <= n; ++j )
		pos[ ab[j][0]%i ][ ab[j][1]%i ][ ab[j][2]%i ]++;

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

}
				
		

int main()
{
	int i,j;
	char buff[13];
	int nm;
	int a,b,c;
	freopen("puteri.in","r",stdin);
	freopen("puteri.out","w",stdout);

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

	for ( i = 1; i <= n; ++i )
	{
		/*
		gets( buff );
		nm = strlen(buff);
		for ( j=0; buff[j] != ' '; ++j )
		{
			ab[i][0]*= 10;
			ab[i][0]+= buff[j]-'0';
		}
		j++;
		for ( ; buff[j] != ' '; ++j )
		{
			ab[i][1]*= 10;
			ab[i][1]+= buff[j]-'0';
		}
		j++;
		for ( ; j < nm; ++j )
		{
			ab[i][2]*= 10;
			ab[i][2]+= buff[j]-'0';
		}*/
		scanf("%d %d %d\n", &a, &b, &c);
		ab[i][0] = a;
		ab[i][1] = b;
		ab[i][2] = c;
	}
	
	back(1,1,-1);
		

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

	return 0;
}