Pagini recente » Cod sursa (job #176885) | infolimpiada | Cod sursa (job #1550053) | Cod sursa (job #587025) | Cod sursa (job #276489)
Cod sursa(job #276489)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin;
ofstream fout;
typedef unsigned int uint;
typedef unsigned long long;
typedef unsigned char byte;
namespace Recursive {
long gcd(long first, long second) {
if(second == 0)
return first;
else
return gcd(second, first%second);
}
}
namespace Iterative {
long gcd(long first, long second) {
long temp;
while(second != 0) {
temp = second;
second = first%second;
first = temp;
}
return first;
}
}
int main(int argc, char * argv[]) {
const char * inFile = "euclid2.in";
const char * outFile = "euclid2.out";
fin.open(inFile);
fout.open(outFile);
if(!fin || !fout) {
cout << "Error opening files!" << endl;
return -1;
}
// Do ya thing
long nPairs;
long first, second;
fin >> nPairs;
for(uint i = 0; i < nPairs; i++) {
fin >> first;
fin >> second;
fout << Iterative::gcd(first,second) << endl;
}
fout.close();
fin.close();
//system("PAUSE");
return 0;
}