Pagini recente » Cod sursa (job #1480718) | Cod sursa (job #1601752) | Cod sursa (job #538158) | Cod sursa (job #578220) | Cod sursa (job #1742266)
#include <fstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("puteri.in");
ofstream fout("puteri.out");
const int dim = 100005;
const int vmax = 128;
const int expmax = 64;
int n, a[dim], b[dim], c[dim];
int dp[expmax + 1][expmax + 1][expmax + 1];
int modulo[vmax + 5];
long long Calc(int mod) {
memset(dp, 0, sizeof dp);
for (int i = 0; i <= vmax; ++i)
modulo[i] = i % mod;
long long ret = 0;
for (int i = 1; i <= n; ++i) {
int x = modulo[mod - modulo[a[i]]], y = modulo[mod - modulo[b[i]]], z = modulo[mod - modulo[c[i]]];
if (x <= expmax && y <= expmax && z <= expmax)
ret += dp[x][y][z];
dp[modulo[a[i]]][modulo[b[i]]][modulo[c[i]]]++;
}
return ret;
}
int pinexCoef[vmax + 5];
bool sieve[vmax + 5];
long long Sieve(void) {
long long ret = 0;
memset(sieve, false, sizeof sieve);
memset(pinexCoef, -1, sizeof pinexCoef);
for (int i = 2; i <= vmax; ++i) {
if (!sieve[i]) {
for (int j = i; j <= vmax; j += i)
pinexCoef[j] *= -1, sieve[j] = true;
for (int j = i * i; j <= vmax; j += i * i)
pinexCoef[j] = 0;
}
if (pinexCoef[i])
ret += pinexCoef[i] * Calc(i);
}
return ret;
}
int main() {
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i] >> b[i] >> c[i];
fout << Sieve() << '\n';
return 0;
}
//Trust me, I'm the Doctor!