Codechef : Problem name "FIND A and B" solution in C#
===========================Solution==========================
using System;
public class Test
{
public static void Main()
{
int t=Convert.ToInt32(Console.ReadLine());
for(int j=0;j<t;j++){
string[] array=Console.ReadLine().Split(' ');
int X=Convert.ToInt32(array[0]);
int Y=Convert.ToInt32(array[1]);
int Z=Convert.ToInt32(array[2]);
bool flag=false;
int A=0;
int B=0;
int[] arrayInt={X,Y,Z};
for(int i=0;i<3;i++)
{
B= arrayInt[i];
if(i==0)
A= arrayInt[i+1]*arrayInt[i+2];
else if(i==1)
A=arrayInt[i-1]*arrayInt[i+1];
else if(i==2)
A=arrayInt[i-1]*arrayInt[i-2];
if(A%B==0)
{
flag=true;
Console.WriteLine(A+" "+B);
break;
}
else{
flag=false;
}
}
if(flag==false)
Console.WriteLine(-1);
}
}
}
using System; public class Test { public static void Main() { int t=Convert.ToInt32(Console.ReadLine()); for(int j=0;j<t;j++){ string[] array=Console.ReadLine().Split(' '); int X=Convert.ToInt32(array[0]); int Y=Convert.ToInt32(array[1]); int Z=Convert.ToInt32(array[2]); bool flag=false; int A=0; int B=0; int[] arrayInt={X,Y,Z}; for(int i=0;i<3;i++) { B= arrayInt[i]; if(i==0) A= arrayInt[i+1]*arrayInt[i+2]; else if(i==1) A=arrayInt[i-1]*arrayInt[i+1]; else if(i==2) A=arrayInt[i-1]*arrayInt[i-2]; if(A%B==0) { flag=true; Console.WriteLine(A+" "+B); break; } else{ flag=false; } } if(flag==false) Console.WriteLine(-1); } } }
using System; public class Test { public static void Main() { int t=Convert.ToInt32(Console.ReadLine()); for(int j=0;j<t;j++){ string[] array=Console.ReadLine().Split(' '); int X=Convert.ToInt32(array[0]); int Y=Convert.ToInt32(array[1]); int Z=Convert.ToInt32(array[2]); bool flag=false; int A=0; int B=0; int[] arrayInt={X,Y,Z}; for(int i=0;i<3;i++) { B= arrayInt[i]; if(i==0) A= arrayInt[i+1]*arrayInt[i+2]; else if(i==1) A=arrayInt[i-1]*arrayInt[i+1]; else if(i==2) A=arrayInt[i-1]*arrayInt[i-2]; if(A%B==0) { flag=true; Console.WriteLine(A+" "+B); break; } else{ flag=false; } } if(flag==false) Console.WriteLine(-1); } } }
Comments
Post a Comment