Cutting Recipes Problem

I was trying to solve this problem: https://www.codechef.com/problems/RECIPE
I know it can be solved by GCD, but trying something different.
It gives correct output of sample input, but while submitting it shows Wrong Answer.
Can anyone help me out what’s the problem?

    #include <iostream>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t, n, i, a[50], min;
    bool flag;
    cin >> t;
    while(t--) {
        flag = true;
        cin >> n;
        for(i=0; i<n; i++)
            cin >> a[i];
        //FINDING MINIMUM
        min = a[0];
        for(i=1; i<n; i++)
            if(a[i] < a[0])
                min = a[i];
        //CHECKING IF THERE ARE FRACTIONS
        for(i=0; i<n; i++)
            if(a[i]%min!= 0)
                flag = false;
        //THIS WILL BE EQUIVALENT TO GCD
        //IF NO FRACTIONS, DIVIDE ALL ELEMENTS BY MINIMUM
        if(flag == true)
            for(i=0; i<n; i++)
                a[i] /= min;
        for(i=0; i<n; i++)
            cout << a[i] << " ";
        cout << endl;
    }
	return 0;
}

Consider the testcase:

1
3
6 9 12