Pagini recente » Cod sursa (job #1743543) | Cod sursa (job #431448) | Cod sursa (job #180976) | Cod sursa (job #2270912) | Cod sursa (job #122289)
Cod sursa(job #122289)
#include <stdio.h>
#include <string.h>
const int N_MAX = 100010;
struct putere {
char a, b, c;
} v[N_MAX];
int nr[130][130][130];
char step[130][130][130];
int is[130];
int main()
{
freopen("puteri.in", "r", stdin);
#ifndef _SCREEN_
freopen("puteri.out", "w", stdout);
#endif
int N, i, j;
scanf("%d\n", &N);
for (i = 1; i <= N; i ++) scanf("%d %d %d\n", &v[i].a, &v[i].b, &v[i].c);
memset(is, 0, sizeof(is));
for (i = 2; i <= 130; i ++) {
if (is[i] == 0) {
for (j = i + i; j <= 130; j += i) {
if ((is[j] != -1) && j % (i * i) != 0) is[j] ++;
else is[j] = -1;
}
}
}
int nrdiv, fin = 0, rez, x, y, z, stp = 1;
for (i = 2; i <= 128; i ++) {
if (is[i] >= 0) {
nrdiv = is[i];
if (nrdiv == 0) nrdiv ++;
for (j = 1; j <= N; j ++) {
x = v[j].a % i, y = v[j].b % i, z = v[j].c % i;
if (step[x][y][z] < stp) {
step[x][y][z] ++;
nr[x][y][z] = 1;
} else nr[x][y][z] ++;
}
rez = 0;
for (j = 1; j <= N; j ++) {
x = v[j].a % i, y = v[j].b % i, z = v[j].c % i;
if ((2 * x) % i == 0 && (2 * y) % i == 0 && (2 * z) % i == 0) {
rez += nr[x][y][z] * (nr[x][y][z] - 1) / 2;
} else rez += nr[x][y][z] * nr[(i - x) % i][(i - y) % i][(i - z) % i];
nr[x][y][z] = 0;
nr[(i - x) % i][(i - y) % i][(i - z) % i] = 0;
}
if (nrdiv % 2 == 1) fin += rez;
else fin -= rez;
stp ++;
}
}
printf("%d\n", fin);
return 0;
}