Problem code:-RECIPE

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve()
{
int n;
cin>>n;
vector<int>v(n);
for(int i=0;i<n;i++)
{
    cin>>v[i];
}

bool array=true;
int d;
d=__gcd(v[0],v[1]);
double frac;
for(int i=0;i<n-1;i++)
{
    frac=(double)(v[i+1]/d);
    if(ceil(frac)!=floor(frac))
    {
        array=false;
        break;
    }
}
if(array)
{
    for(int i=0;i<n;i++)
    {
        cout<<v[i]/d<<" ";
    }
    cout<<endl;
}
else
{
    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
}

int main() 
{
fast;
int t;
cin>>t;
while(t--)
   { 
  solve();
   }
  return 0;
}

problem code:- RECIPE
can anyone help me what is the problem.

u can just find the gcd of the whole array and divide all the elements of the array by the gcd .

Suppose,
int arr[] = {2,3,4,5,6};
int ans = arr[0];
for(int i=1;i<n;i++)
{
ans = __gcd(ans,arr[i]);
}
// now…divide the whole array by this gcd that is stored in ans

1 Like

thanks for the help

1 Like

welcome