Mai intai trebuie sa te autentifici.
Cod sursa(job #232409)
| Utilizator | Data | 15 decembrie 2008 10:48:46 | |
|---|---|---|---|
| Problema | Pairs | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.9 kb |
#include <iostream>
#include <fstream>
#include <cstdlib> // for exit function
#include <algorithm>
#include <math.h>
using namespace std;
long cmmdc(long a, long b)
{
return ( b == 0 ? a : cmmdc(b, a % b) );
}
int main()
{
ifstream indata;
ofstream outdata;
indata.open("pairs.in");
outdata.open("pairs.out");
if(!indata) {
//cerr << "Error: file could not be opened" << endl;
exit(1);
}
long n;
indata >> n;
long vec[100001];
//cout << "n=" << n << endl;
for (long i = 0; i < n; i++)
{
indata >> vec[i];
//cout << vec[i] << " ";
}
//cout << endl;
indata.close();
long nr = 0;
for (long i = 0; i < n; i++)
{
for (long j = i + 1; j < n; j++)
{
if (vec[i] % 2 == 0 && vec[j] % 2 == 0)
continue;
else if (cmmdc(vec[i], vec[j]) == 1)
++nr;
}
}
//cout << "nr=" << nr << endl;
outdata << nr;
outdata.close();
return 0;
}
