Cod sursa(job #3248784)

Utilizator malex5Muresan Alexandru malex5 Data 13 octombrie 2024 11:00:34
Problema Pairs Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("pairs.in");
ofstream fout("pairs.out");

int cmmdc(int a, int b) {
    while(b) {
        int r = a%b;
        a=b;
        b=r;
    }
    return a;
}

int main(void) {
    long long cnt=0;
    long long n, v[1000001];
    fin >> n;
    for(int i =0;i<n;++i) {
        fin>>v[i];
    }

     for(int i =0;i<n-1;++i) {
         for(int j =i+1;j<n;++j) {
             //cout << v[i] << " " << v[j] << " ";
             if(cmmdc(v[i], v[j]) == 1) {
                 //cout << "DA";
                 ++cnt;
             }
             //cout << endl;
         }
     }
    fout << cnt;
    fin.close();
    fout.close();

}