Cod sursa(job #3220545)

Utilizator unomMirel Costel unom Data 4 aprilie 2024 07:19:46
Problema Puteri Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <ctype.h>

using namespace std;

class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;

	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}

public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};

struct el
{
    int a, b, c;
};

InParser in("puteri.in");
ofstream out("puteri.out");
int n, ans;
int w[130][130][130];
el v[100005];

int main()
{
    in>>n;

    for(int i = 1; i<=n; i++)
    {
        in>>v[i].a>>v[i].b>>v[i].c;
    }

    for(int i = 0; i<=128; i++)
    {
        for(int j = 0; j<=128; j++)
        {
            for(int k = 0; k<=128; k++)
            {
                if(__gcd(__gcd(i, j), k) > 1)
                {
                    w[i][j][k] = 1;
                }
            }
        }
    }

    int a, b, c;
    for(int i = 1; i<=n; i++)
    {
        for(int j = i+1; j<=n; j++)
        {
            a = v[i].a + v[j].a;
            b = v[i].b + v[j].b;
            c = v[i].c + v[j].c;

            if(w[a][b][c] == 1)
            {
                //out<<i<<" -> "<<j<<'\n';
                ans++;
            }
        }
    }

    out<<ans;

    return 0;
}