Cod sursa(job #1824180)

Utilizator 1475369147896537415369Andrei Udriste 1475369147896537415369 Data 7 decembrie 2016 15:02:03
Problema Algoritmul lui Euclid Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.44 kb
#include<stdio.h>

int main(){

FILE *file1, *file2;
int T, i, min, A, B;

file1 = fopen("euclid2.in", "r");
file2 = fopen("euclid2.out", "w");

fscanf(file1, "%d", &T);

while(T--){

    fscanf(file1, "%d", &A);
    fscanf(file1, "%d", &B);

    min = (A>=B) ? B : A;

    for(i=min; i>1; i--){
        if(!(A%i) && !(B%i)){
            fprintf(file2, "%d\n", i);
            break;
        }
    }

}

return 0;
}