My code is giving correct output for every possible test case but still while submitting the code I get WA error. Why?Here is 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
{
public static void main (String[] args) throws java.lang.Exception
{

    Scanner scan=new Scanner(System.in);
    int t=scan.nextInt();
    while(t-->0)
    {
        int n=scan.nextInt();
        Integer arr[]=new Integer[n];
        for(int i=0;i<n;i++)
        arr[i]=scan.nextInt();
        int min=Collections.min(Arrays.asList(arr));
        
        //check if evry element is divisible by min
        int count=0;
        for(int i=0;i<n;i++)
        if(arr[i]%min==0)
        count++;
        
        //finding ratios
        if(count==n)
        {
            for(int i=0;i<n;i++)
            arr[i]=arr[i]/min;
        }
        for(int i=0;i<n;i++)
        System.out.print(arr[i]+" ");
        System.out.println();
        
    }
    
}

}

pls provide the link of question too.

Hi @aditi_12345678.
The logic for your program is incorrect. For example, consider the test case-

2 6 9  

Your program will give the output-

6 9  

While the correct answer is -

2 3  

Try to figure out your mistake. If you are stuck, take this -

HINT:

Click to view

Think in terms of [GCD][1] of the numbers.

If you are still stuck, here -

SOLUTION:

Click to view

We want the ratio of the numbers to be the same in the end. Also, after dividing, they must be as small as possible. So find out the overall Highest Common Factor (GCD) of all the numbers and divide each number by it. This will be the solution. [Here][2] is my code

Hope this helped :slight_smile:
[1]: https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
[2]: https://www.codechef.com/viewsolution/23622301

Question link - https://www.codechef.com/problems/RECIPE. Submission link - https://www.codechef.com/viewsolution/23621637.