Pagini recente » Istoria paginii runda/2014oni10/clasament | Autentificare | Monitorul de evaluare | fmi-no-stress-9/solutii | Cod sursa (job #110003)
Cod sursa(job #110003)
#include<fstream>
using namespace std;
int n,a[1000],p;
int prime(int x,int y)
{
while(x!=y)
{
if(x > y)
x = x-y;
if(y > x)
y = y-x;
}
if(y == 1) return 1;
else return 0;
}
int main()
{
ifstream fin("pairs.in");
ofstream fout("pairs.out");
int i,j;
fin>>n;
for(i = 1; i <= n; i++)
fin>>a[i];
for(i = 1; i <= n; i++)
{
for(j = i+1; j <= n; j++)
if(prime(a[i],a[j]) == 1)
{
fout<<a[i]<<" "<<a[j]<<"\n";
p++;
}
}
fout<<p;
fin.close();
fout.close();
}