Cod sursa(job #3292628)

Utilizator EricRaiaEricRaia EricRaia Data 8 aprilie 2025 19:36:44
Problema Puteri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream fin("puteri.in");
ofstream fout("puteri.out");

const int MAXN = 100005;
const int MAXABC = 130;
using LL = long long;
int N, a[MAXN], b[MAXN], c[MAXN];
int n[MAXABC/2][MAXABC/2][MAXABC/2];
LL rez;
int m[MAXABC];

void Read();
void Solve();

int main()
{
    Read();
    Solve();

    fout << rez;

    fin.close();
    fout.close();
    return 0;
}

void Read()
{
    int i;

    fin >> N;
    for ( i = 1; i <= N; i++ )
    {
        fin >> a[i] >> b[i] >> c[i];
    }
}

void Solve()
{
    int i, j, p1, p2, p3, d, x;
    LL sgn;
    int op1, op2, op3;

    for ( d = 2; d <= 128; d++ )
    {
        x = d; sgn = -1;
        for ( i = 2; x > 1; i++ )
        {
            if ( x % i == 0 ){
                x /= i;
                if ( x % i == 0 ) break;
                sgn = (sgn == -1 ? 1 : -1);
            }
        }
        if ( x > 1 ) continue;
        for ( i = 0; i <= 124; i++ )
            m[i] = i % d;
        for ( i = 1; i <= N; i++ ){
            p1 = ( d - m[a[i]] );
            p2 = ( d - m[b[i]] );
            p3 = ( d - m[c[i]] );
            if ( p1 == d ) p1 = 0;
            if ( p2 == d ) p2 = 0;
            if ( p3 == d ) p3 = 0;
            if ( p1 < 65 && p2 < 65 && p3 < 65 )
                rez = ( rez + sgn*( 1LL * n[p1][p2][p3] ) );
            n[m[a[i]]][m[b[i]]][m[c[i]]]++;
        }
        memset(n, 0, sizeof(n));
    }

    return 0;
}