Pagini recente » Cod sursa (job #393348) | Cod sursa (job #27271)
Cod sursa(job #27271)
#include<stdio.h>
#include<algorithm>
const int pr[40] = {0, 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, 10000};
const int maxn = 100001;
const int maxn2 = 128;
short a[maxn];
short a1[maxn];
int j;
long long solf;
long long sol[maxn];
int n;
int i;
short b[maxn];
short c[maxn];
short mat[maxn2][maxn2][maxn2];
int prod;
int nr1;
int calc(int i)
{
int sol = 0;
int j = 0;
for(j = 1; j <= n; ++j)
{
sol += mat[(i-(a[j]%i))%i][(i-(b[j]%i))%i][(i-(c[j]%i))%i];
mat[a[j]%i][b[j]%i][c[j]%i]++;
}
for(j = 1; j <= n; ++j)
{
mat[a[j]%i][b[j]%i][c[j]%i]--;
}
return sol;
}
void bkt(int i)
{
if (pr[i] < 128 && prod * pr[i] <= 128)
{
for(a1[i] = 0; a1[i] <= 1; ++a1[i])
{
if (a1[i] == 1)
{
nr1++;
prod *= pr[i];
}
bkt(i+1);
if (a1[i] == 1)
{
nr1--;
prod /= pr[i];
}
}
}
else
{
if (prod < 128 && prod != 1)
{
if (nr1 % 2 == 1) solf += calc(prod);
else solf -= calc(prod);
}
}
}
int main()
{
freopen("puteri.in","r",stdin);
freopen("puteri.out","w",stdout);
scanf("%d",&n);
prod = 1;
for(i = 1; i <= n; ++i)
{
scanf("%hd %hd %hd", &a[i],&b[i],&c[i]);
}
bkt(1);
printf("%lld\n",solf);
return 0;
}