Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it is rectangular in nature. Santosh comes to know that he will get more money if he sells square shaped plots. So keeping this in mind, he decides to divide his land into minimum possible number of square plots, such that each plot has the same area, and the plots divide the land perfectly. He does this in order to get the maximum profit out of this.
So your task is to find the minimum number of square plots with the same area, that can be formed out of the rectangular land, such that they divide it perfectly.
###Input
###Output For each test case, print the minimum number of square plots with equal area, such that they divide the farm land perfectly, in a new line.
###Constraints
1≤T≤20
1≤M≤10000
1≤N≤10000
###Sample Input:
2
10 15
4 6
###SampleOutput:
6
6
# cook your dish here
import math
for _ in range(int(input())):
n,m = map(int,input().split())
a = math.gcd(n,m)
print((m//a)*(n//a))
#include <iostream>
using namespace std;
int main() {
int t = 0;
int n = 0;
int m = 0;
cin >> t;
for (int c = 0; c < t; c++)
{
int n,m; cin>>n>>m;
int a = n*m;
int mx = 0;
for(int i = 1;i<=m;i++){
if(m%i==0&&n%i==0&&i>=mx){
mx = i;
}
}
cout<<(m/mx)*(n/mx)<<endl;
}
// your code goes here
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t,n,m;
t = sc.nextInt();
while(t-->0)
{
n = sc.nextInt();
m = sc.nextInt();
int cont=0;
for (int i=m;i>0;i--)
{
if (n%i==0&&m%i==0)
{
cont=i;
break;
}
}
System.out.println(m*n/(cont*cont));
}
}
}
In our experience, we suggest you solve this Farmer And His Plot CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Farmer And His Plot CodeChef Solution
I hope this Farmer And His Plot CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>