Cod sursa(job #551110)

Utilizator feelshiftFeelshift feelshift Data 10 martie 2011 13:13:21
Problema Pairs Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
// http://infoarena.ro/problema/pairs
#include <fstream>
using namespace std;

#define maxSize 100001

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

int length;
int total;
int number[maxSize];

int cmmdc(int a,int b);

int main() {
    in >> length;
    for(int i=1;i<=length;i++)
        in >> number[i];

    for(int i=1;i<=length;i++)
        for(int k=i+1;k<=length;k++)
            if(cmmdc(number[i],number[k]) == 1)
                total++;

    out << total << "\n";

    return (0);
}

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

    return a;
}