Cod sursa(job #2707968)

Utilizator marius.tileaTilea Marius marius.tilea Data 18 februarie 2021 08:30:42
Problema Puteri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.58 kb
# include <bits/stdc++.h>

# define md(x) md[x]

# define ll long long

using namespace std;

class Reader {

public:

Reader(const string& filename):

m_stream(filename),

m_pos(kBufferSize - 1),

m_buffer(new char[kBufferSize]) {

next();

}

Reader& operator>>(int& value) {

value = 0;

while (current() < '0' || current() > '9')

next();

while (current() >= '0' && current() <= '9') {

value = value * 10 + current() - '0';

next();

}

return *this;

}

private:

const int kBufferSize = 32768;

char current() {

return m_buffer[m_pos];

}

void next() {

if (!(++m_pos != kBufferSize)) {

m_stream.read(m_buffer.get(), kBufferSize);

m_pos = 0;

}

}

ifstream m_stream;

int m_pos;

unique_ptr<char[]> m_buffer;

};

Reader fi("puteri.in");

ofstream fo("puteri.out");

const int pw[] = {-1,1};

const int nmax = 1 << 7;

int md[nmax + 777];

int s[65][65][65];

int ok(int p)

{

bool k = 0;

for (int i = 2;i*i <= p;++i)

if (!(p%i))

{

p /= i;

if (!(p%i)) return 0;

k = 1 - k;

}

if (p > 1) k = 1 - k;

return pw[k];

}

int main(void)

{

int n;

fi>>n;

int * a;

int * b;

int * c;

a = new int [n+1];

b = new int [n+1];

c = new int [n+1];

int nx = 0;

for (int i = 1;i <= n;++i) fi>>a[i]>>b[i]>>c[i];

ll ans = 0;

for (int mod = 2;mod <= 128;++mod)

if (ok(mod))

{

int r = ok(mod);

for (int j = 0;j <= 128;++j) md[j] = j % mod;

memset(s,0,sizeof(s));

for (int i = 1;i <= n;++i)

{

int x = md(mod - md(a[i])),y = md(mod - md(b[i])),z = md(mod - md(c[i]));

if (x < 65 && y < 65 && z < 65)

ans += r * s[x][y][z];

++s[md(a[i])][md(b[i])][md(c[i])];

}

}

return fo << ans << '\n',0;

}