Cod sursa(job #3238573)

Utilizator mariusfilip_andreiFilip Marius-Andrei mariusfilip_andrei Data 26 iulie 2024 18:18:10
Problema Pairs Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<stdio.h>
int euclid(int a,int b)
{
    int x;
    while(b!=0)
    {
        x=b;
        b=a%b;
        a=x;
    }
    return a;
}
int main()
{
    FILE *f=fopen("cifra2.in","r");
    FILE *g=fopen("cifra2.out","w");
    int a,b[100],c,d=0,e;
    fscanf(f,"%d",&a);
    for(int i=1;i<=a;i++)
    {
        fscanf(f,"%d",&e);
        if(e>1&&e<1000000)
        b[i]=e;
    }
    for(int i=1;i<a;i++)
        for(int j=1+i;j<=a;j++)
        {
            c=euclid(b[i],b[j]);
            if(c==1)
                d++;
        }
        fprintf(g,"%d",d);
}