Cod sursa(job #2462170)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 26 septembrie 2019 20:51:19
Problema Puteri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <cstdio>
#include <cctype>

using namespace std;

const int SIZE = 1 << 17;
int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}


typedef long long ll;
const int N = 100000 + 7;
const int L = 128;

int n;
int x[N], y[N], z[N];
ll dp[L];
int f[L][L][L];

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

  n = Read();
  for (int i = 1; i <= n; i++) {
    x[i] = Read();
    y[i] = Read();
    z[i] = Read();
  }

  for (int mod = L - 1; mod >= 2; mod--) {
    for (int mod2 = 2 * mod; mod2 < L; mod2 += mod) {
      dp[mod] -= dp[mod2];
    }
    for (int i = 1; i <= n; i++) {
      int a = x[i] % mod;
      int b = y[i] % mod;
      int c = z[i] % mod;
      int ia = (mod - a) % mod;
      int ib = (mod - b) % mod;
      int ic = (mod - c) % mod;
      dp[mod] += f[ia][ib][ic];
      f[a][b][c]++;
    }
    for (int i = 1; i <= n; i++) {
      f[x[i] % mod][y[i] % mod][z[i] % mod]--;
    }
  }

  ll ans = 0;
  for (int mod = 2; mod < L; mod++) {
    ans += dp[mod];
  }
  printf("%I64d\n", ans);

  return 0;
}