Here is my code…
Question Link
#include <bits/stdc++.h>
using namespace std;
int isDivisible(int a, int b)
{
if (a > b)
{
if (a % b == 0)
{
return 1;
}
else
{
return 0;
}
}
else
{
if (b % a == 0)
{
return 1;
}
else
{
return 0;
}
}
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout<<endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int arr[n];
bool flag = false;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int temp[n] = {0};
for (int i = 0; i < n; i++)
{
temp[i] = {arr[i]};
}
sort(arr, arr + n);
for (int i = 1; i < n; i++)
{
if(isDivisible(arr[0],arr[i])==1){
flag = true;
}
else{
flag = false;
break;
}
}
if (flag == true)
{
int ans[n] = {0};
for (int i = 0; i < n; i++)
{
ans[i] = {temp[i]/arr[0]};
}
printArray(ans, n);
}
else
{
printArray(temp, n);
}
}
return 0;
}