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.

/* 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(;
    int t=scan.nextInt();
        int n=scan.nextInt();
        Integer arr[]=new Integer[n];
        for(int i=0;i<n;i++)
        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++)
        //finding ratios
            for(int i=0;i<n;i++)
        for(int i=0;i<n;i++)
        System.out.print(arr[i]+" ");


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 -


Click to view

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

If you are still stuck, here -


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:

Question link - Submission link -