Cod sursa(job #1337551)

Utilizator wGEORGEWGeorge Cioti wGEORGEW Data 9 februarie 2015 10:41:48
Problema Puteri Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <fstream>
#include <algorithm>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
 
ifstream fin("puteri.in");
ofstream fout("puteri.out");
 
struct tr {
    int a, b, c;
    tr(int _a = 0, int _b = 0, int _c = 0) {
        a = _a;
        b = _b;
        c = _c;
    }
};
 
vector<tr> v;
 
int d[65][65][65];
int r[130];
 
int get(int x) {
    int ans = 0;
    int cx = x;
    for(int d = 2; d * d <= x; d++) {
        int p = 0;
        while(cx % d == 0) {
            cx /= d;
            p++;
        }
        if(p > 1) {
            return -1;
        }
        if(p == 1) {
            ans++;
        }
    }
    if(cx > 1) {
        ans++;
    }
    return ans;
}
 
int main() {
    int n;
    fin >> n;
    v.reserve(n + 1);
    for(int i = 1; i <= n; i++) {
        int a, b, c;
        fin >> a >> b >> c;
        v.push_back(tr(a, b, c));
    }
 
    long long ans = 0;
    for(int i = 2; i <= 128; i++) {
        int val = get(i);
        if(val != -1) {
            int sg = 1;
 
            memset(d, 0, sizeof(d));
 
            for(int j = 1; j < 130; j++) {
                r[j] = j % i;
            }
 
            if(val % 2 == 0) {
                sg = -1;
            }
 
            for(auto it : v) {
                int a = r[i - r[it.a]];
                int b = r[i - r[it.b]];
                int c = r[i - r[it.c]];
                if(a < 65 && b < 65 && c < 65) {
                    ans += sg * d[a][b][c];
                }
                d[r[it.a]][r[it.b]][r[it.c]]++;
            }
        }
    }
 
    fout << ans << '\n';
 
    return 0;
}