Cod sursa(job #2304398)

Utilizator frodobiosif aug frodob Data 17 decembrie 2018 23:18:39
Problema Pairs Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

//int gcd(int a, int b);

int main() {
  fstream fin("pairs.in", ios::in);
  fstream fout("pairs.out", ios::out);
  // citesc N
  int N;
  fin>>N;
  // aloc si citest sirul de numere
  int* elements = new int[N];
  for(int i = 0; i<N; i++)
    fin>>elements[i];
  long long count = 0LL;
  for (int i = 0; i<N-1; i++)
    for (int j = i+1; j<N; j++)
      if (1==__gcd(elements[i], elements[j])) {
        count++;
        //cout<<"("<<elements[i]<<", "<<elements[j]<<")"<<endl;
      }
  fout<<count;
  // the end
  fin.close();
  fout.close();
  delete[] elements;
  return 0;
}