Cod sursa(job #1408594)

Utilizator atatomirTatomir Alex atatomir Data 30 martie 2015 09:33:41
Problema Puteri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

#define maxN 100012
#define maxV 70

struct Triple{
    long a,b,c;

};

long n,i,Ans;
Triple Tr[maxN];
long how[maxV][maxV][maxV],def[maxV*2];

long getCnt(long val){
    long ans=0;
    for(long i=2;i*i<=val;i++){
        long cnt=0;
        while(val%i==0) {cnt++; val/=i;}
        if(cnt>1) return -1;
        if(cnt) ans++;
    }
    if(val!=1) ans++;
    return ans;
}

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

    scanf("%ld",&n);
    for(i=1;i<=n;i++) scanf("%ld%ld%ld",&Tr[i].a,&Tr[i].b,&Tr[i].c);

    for(long pas = 2;pas<maxV*2;pas++){
        long long sg = getCnt(pas);
        if(sg==-1) continue;
        if(sg%2==0) sg=-1; else sg=1;

        for(i=1;i<maxV*2;i++) def[i] = i%pas;

        memset(how,0,sizeof(how));
        for(i=1;i<=n;i++){
            Triple tmp = Tr[i];
            tmp.a=def[tmp.a]; tmp.b=def[tmp.b] ; tmp.c=def[tmp.c];

            tmp.a = pas - tmp.a;
            tmp.b = pas - tmp.b;
            tmp.c = pas - tmp.c;

            tmp.a=def[tmp.a]; tmp.b=def[tmp.b] ; tmp.c=def[tmp.c];

            if(tmp.a < maxV && tmp.b < maxV && tmp.c < maxV) Ans += sg*how[tmp.a][tmp.b][tmp.c];
            tmp = Tr[i]; tmp.a=def[tmp.a]; tmp.b=def[tmp.b] ; tmp.c=def[tmp.c];
            how[tmp.a][tmp.b][tmp.c]++;
        }
    }

    printf("%lld",Ans);

    return 0;
}