Pagini recente » Cod sursa (job #94419) | Cod sursa (job #1417924) | Cod sursa (job #2088478) | Cod sursa (job #1589296) | Cod sursa (job #25802)
Cod sursa(job #25802)
#include <cstdio>
#define dim 100001
long N, Sol;
struct powers
{ int i, j, k; } P[dim];
int putere( int, int );
int cmmdc( int, int );
int main()
{
freopen("puteri.in", "r", stdin);
freopen("puteri.out", "w", stdout);
scanf("%d", &N);
long i, j;
for(i=1; i<=N; ++i)
scanf("%d %d %d", &P[i].i, &P[i].j, &P[i].k);
for(i=1; i<N; ++i)
for(j=i+1; j<=N; ++j)
Sol += putere(i, j);
printf("%ld", Sol);
fclose(stdin);
fclose(stdout);
return 0;
}
int cmmdc( int x, int y )
{
int r;
while( y )
{
r = x % y;
x = y;
y = r;
}
return x;
}
int putere( int i, int j )
{
int a = P[i].i + P[j].i;
int b = P[i].j + P[j].j;
int c = P[i].k + P[j].k;
int z = 0, x, y;
if( !a ) ++ z;
if( !b ) ++ z;
if( !c ) ++ z;
if( z == 2 ) return 1;
if( z == 1 )
{
if( !a )
x = cmmdc(b, c);
if( !b )
x = cmmdc(a, c);
if( !c )
x = cmmdc(a, b);
if( x > 1 ) return 1;
else return 0;
}
if( !z )
{
x = cmmdc(a, b);
y = cmmdc(x, c);
if( y > 1 ) return 1;
else return 0;
}
}