My issue
i first initialize all the three integers ,then i compared the two integers whether they are equal if they are then min sum will be 2*(one of the no) and if not then i took max if the two nos in o and min of the two nos in p, After that by using for loop I find the gcd of o and p and store it in o and find the lcm of o and p and store it in p for k times ,after k times I add the final o and p to find min sum…
My code
/* 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
{
static int gcd(int a,int b){
if (b == 0)
return a;
// call the gcd() method recursively by
// replacing a with b and b with
// difference(a,b) as long as b != 0
else
return gcd(b, Math.abs(a - b));
}
static int lcm(int l,int m){
return m;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int x=sc.nextInt();int y=sc.nextInt();int k=sc.nextInt();int o=Math.max(x,y);
int p=Math.min(x,y);
if(x==y)System.out.println(2*x);
else{
for(int i=0;i<k;i++){
o=gcd(o,p);p=lcm(o,p);
}
System.out.println(o+p);
}
}
}
}
Problem Link: GCDLM Problem - CodeChef