cutting recipes (RECIP) question getting wrong answer

question link

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int sieve(int *a,int n)
{
	int sz=sqrt(n);
	a[0]=a[1]=0;
	for(int i=2;i<=sz;i++)
	{	
		if(a[i]!=0)
		{
			int k=i+i;
			while(k<n)
			{
				a[k]=0;
				k+=i;
			}
		}
	}
	sz=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]!=0)
		{
			a[sz]=i;
			sz++;
		}
	}
	return sz;
}
void divide(int *arr,int n,int product)
{
	for(int i=0;i<n;i++)
		arr[i]/=product;
}
int main(int argc, char const *argv[])
{
	int t;
 	cin>>t;
	int n;
	int size=40;
	int a[size];
	for(int i=0;i<size;i++)
		a[i]=1;

	int sz=sieve(a,size);
	//cout<<sz;

	
	while(t--)
	{
		cin>>n;
		int arr[n];
		for(int i=0;i<n;i++)
			cin>>arr[i];
		for(int i=0;i<sz;)
		{
			int j;
			for(j=0;j<n;j++)
			{
				if(arr[j]%a[i]!=0)
				{
					i++;
					break;
				}					
			}
			if(j==n)
			divide(arr,n,a[i]);
		}
		for(int i=0;i<n;i++)
			cout<<arr[i]<<" ";
		cout<<endl;
	}
	return 0;
}
1 Like

1
2 53 53

1 Like

thanks a ton,i need to think properly