Pagini recente » Cod sursa (job #2914952) | Cod sursa (job #2404655) | Cod sursa (job #27405) | Cod sursa (job #1931124) | Cod sursa (job #109350)
Cod sursa(job #109350)
#include<fstream>
#include<cstdio>
using namespace std;
fstream in("pairs.in",ios::in);
fstream out("pairs.out",ios::out);
unsigned n,k,l;
struct nod{unsigned nr;nod *urm;};
void adauga_nod(nod *&prim)
{prim=new nod;prim->nr=n;prim->urm=NULL;}
void adauga_dupa(nod *q)
{nod *p=new nod;p->nr=n;p->urm=NULL;q->urm=p;}
unsigned cmmdc(int x,int y)
{unsigned r;
while(y){r=x%y;x=y;y=r;}
return x;
}
int verif(nod *q,nod*prim)
{k=0;
int x=prim->nr,y;
for(nod *p=prim;p!=q;p=p->urm)
{y=q->nr;
if(cmmdc(x,y)==1) k++;}
return k;}
int main()
{in>>l;unsigned s=0;nod *prim,*q;in>>n;adauga_nod(prim);q=prim;
for(int i=1;i<=l;i++)
{in>>n;adauga_dupa(q);q=q->urm;s=s+verif(q,prim);
}
out<<s;
return 0;}