this program of mine giving the wrong answer but has been submitted correctly by other users in the solution section
what is the problem?
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int gcdans=0;
int n = sc.nextInt();
int ar[]=new int[n*2];
for(int i=0;i<(n*2);i++){
ar[i]=sc.nextInt();
}
for(int j=0;j<(n*2);j+=2){
gcdans = gcd(ar[j],ar[j+1]);
System.out.println(gcdans+" "+(ar[j]*ar[j+1]/gcdans));
}
}
static int gcd(int a, int b){
if(b==0){
return a;
}else {
return gcd(b, a%b);
}
}
}
I’m beginner to codechef. Please help!
Here’s the problem:- FLOW016 Problem - CodeChef
And my solution:- CodeChef: Practical coding for everyone