HCF -Editorial

[Practice](CodeChef HCF)

Author: Nilprasad Birajdar
Tester: Rushikesh Thakare
Editorialist: Shadab Shaikh

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Meena and Vaibhav had M and N rupees respectively. They have planned to go goa for a trip. So they wanted some extra money to spend on the trip. The parents of Meena and Vaibhav decide to give some extra fixed amount of money. That amount is equal to HCF(Highest Common Factor) of M and N.You have to find that amount.

SOLUTIONS:

Setter's Solution

#include
using namespace std;

int main() {
int n1, n2, k, t;
cin>>t;
for(k=0;k<t;k++){
cin >> n1 >> n2;
while(n1 != n2) {
if(n1 > n2)
n1 -= n2;
else
n2 -= n1;
}
cout << n1<<"\n";
}
return 0;
}