Cod sursa(job #2428608)

Utilizator rd211Dinucu David rd211 Data 5 iunie 2019 21:40:12
Problema Pairs Scor 0
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
using namespace std;
int M[100001];
bool primeIntreEle(int x,int y)
{
    int i,j,r;
    if(x>y)
    {
        i = x;
        j = y;
    }
    else
    {
        i = y;
        j = x;
    }
    r= i%j;
    while(r!=0)
    {
        x = y;
        y = r;
        r = x%y;
    }
    if(y == 1)
        return true;
    else
        return false;
}
bool isValidCombination(int x,int y)
{
    if(x!=y && primeIntreEle(x,y))
        return true;
}
int main()
{
    ifstream fin("pairs.in");
    ofstream fout("pairs.out");
    int n,combs=0;

    fin>>n;
    for(int i = 0;i<n;i++)
        fin>>M[i];
    for(int i = 0;i<n;i++)
        for(int j = i+1;j<n;j++)
            if(isValidCombination(M[i],M[j]))
                combs++;
    fout<<combs;
    return 0;
}