ECAUG201 - Editorial

PROBLEM LINK:

Encoding August’20
Problem

Author: shrivas7
Tester: sandeep1103
Editorialist: shrivas7

DIFFICULTY:

Cakewalk

PREREQUISITES:

Basic Mathematics, LCM

EXPLANATION:

It is given that Chef has coins of denomination N whereas Chefu has coins of denomination M. We are required to find the minimum price of the cakes. In order to do so we must make sure that the price of the cake must be divisible by N and M and also it has be a minimum one. In other words we have to compute the LCM of N and M.

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
	ll t,m,n;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		cout<<((n*m)/__gcd(n,m))<<endl;
	}
	return 0;
} 
Tester's Solution
#include <bits/stdc++.h>
#define ll long long 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ln cout << '\n'
#define mod 1000000007
#define MxN 100005
#define all(x) x.begin(), x.end()
using namespace std;
 
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
 
void solve(){
 
	ll i, j, n, m;
	cin >> n >> m;
 
	cout << (n / gcd(n, m)) * m << endl;
}
int main(){
 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
	#endif
 
	int t = 1;
	cin >> t;
	while(t--)
		solve();
}