Cod sursa(job #2462855)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 27 septembrie 2019 21:57:38
Problema Puteri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>

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;
}

const int N = 100000 + 7;
const int L = 65;
const int T = 2 * L;

int n, ia, ib, ic;
int x[N], y[N], z[N];
int mod[T];
int f[L][L][L];

long long compute(int i) {
  long long dp = 0;
  for (int j = 0; j < T; j++) {
    mod[j] = j % i;
  }
  memset(f, 0, sizeof f);
  for (int j = 1; j <= n; j++) {
    ia = mod[i - mod[x[j]]], ib = mod[i - mod[y[j]]], ic = mod[i - mod[z[j]]];
    if (ia < L && ib < L && ic < L) {
      dp += f[ia][ib][ic];
    }
    f[mod[x[j]]][mod[y[j]]][mod[z[j]]]++;
  }
  return dp;
}

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();
  }

  long long ans = 0;
  for (int i = 2; i < T; i++) {
    int aux = i;
    int sgn = -1;
    for (int j = 2; j <= i; j++) {
      int c = 0;
      while (aux % j == 0) {
        aux /= j;
        c++;
      }
      if (c > 1) {
        sgn = 0;
      }
      if (c) {
        sgn *= -1;
      }
    }
    if (sgn) {
      ans += compute(i) * sgn;
    }
  }

  printf("%lld\n", ans);
  return 0;
}