Pagini recente » Cod sursa (job #902753) | Cod sursa (job #1874702) | Cod sursa (job #1118175) | Istoria paginii runda/redsnow_3 | Cod sursa (job #1497404)
#include <fstream>
using namespace std;
long int cmmdc(long long int x, long long int y)
{
int r; //variabila auxiliara
while (y!=0) //cat timp nu s-a gasit cmmdc
{
r=y; //salvam valoarea lu y in r
y=x%y; //y ia valoarea restului
x=r; //x devine noul y
}
return x;
}
int main()
{
long long int a, b, d, t;
ifstream g ("euclid2.in");
ofstream h ("euclid2.out");
g>>t;
while(t--)
{
g>>a>>b; //citire
//aici puteti pune un for
d=cmmdc(a, b); //functie
if(d!=1)
h<<d<<endl;
else
h<<"1"<<endl;
}
g.close();
h.close();
return 0;
}