Cod sursa(job #1451166)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 16 iunie 2015 12:27:11
Problema Puteri Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <cstdio>
#include <cstring>
#include <algorithm>

#define a first.first
#define b first.second
#define c second

using namespace std;

const int Nmax = 100000;
const int Vmax = 64;

int i , n , rest , mode , ans;
int mat[Vmax+5][Vmax+5][Vmax+5];

pair < pair < int , int > , int > v[Nmax+10];

bool check(int x)
{
    mode = 0;
    for (int i = 2; i * i <= x; ++i)
        if (x % i == 0)
        {
            x /= i;
            if (x % i == 0)
                return false;
            mode++;
        }

    if (x > 1) mode++;

    if (mode & 1) mode = 1; else mode = -1;

    return true;
}


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

    scanf("%d", &n);

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

    for (rest = 2; rest <= (Vmax << 1); ++rest)
    {
        if (!check(rest))
            continue;

        memset(mat , 0 , sizeof(mat));

        for (i = 1; i <= n; ++i)
        {
            int A = (rest - v[i].a) % rest; int B = (rest - v[i].b) % rest; int C = (rest - v[i].c) % rest;
            while (A < 0) A += rest; while (B < 0) B += rest; while (C < 0) C += rest;
            if (A <= Vmax && B <= Vmax && C <= Vmax)
                ans += mode * mat[A][B][C];
            mat[v[i].a%rest][v[i].b%rest][v[i].c%rest]++;
        }
    }

    printf("%d\n", ans);

    return 0;
}