Help me in solving GCDLM problem

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.*;

/* 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
            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(;
		int t=sc.nextInt();
		    int x=sc.nextInt();int y=sc.nextInt();int k=sc.nextInt();int o=Math.max(x,y);
		    int p=Math.min(x,y);
		       for(int i=0;i<k;i++){

Problem Link: GCDLM Problem - CodeChef

for test case
2 3 2
your output is
but the correct output will be