#include<stdio.h>
int main()
{
int t,n,i,j,k,m,a[1000],s[1000],gcd;
scanf("%d",&t);
if(t<=100)
{
for(i=1;i<=t;i++)
{
scanf("%d",&n);
if(n>=2&&n<=50)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
}
gcd=a[0];
for(k=1;k<n;k++)
{
if(a[k]%gcd==0)
{
k++;
}
else{
gcd=a[k]%gcd;
}
}
for(m=0;m<n;m++)
{
s[m]=a[m]/gcd;
printf("%d \n",s[m]);
}
}
}
return 0;
}
please tell me what is wrong with my code it’s working on my system but when I submit it show me wrong answer
#include<stdio.h>
int main()
{
int t,n,i,j,k,m,a[1000],s[1000],gcd;
scanf("%d",&t);
if(t<=100)
{
for(i=1;i<=t;i++)
{
scanf("%d",&n);
if(n>=2&&n<=50)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
}
gcd=a[0];
for(k=1;k<n;k++)
{
if(a[k]%gcd==0)
{
k++;
}
else{
gcd=a[k]%gcd;
}
}
for(m=0;m<n;m++)
{
s[m]=a[m]/gcd;
printf("%d \n",s[m]);
}
}
}
return 0;
}
please tell me what is wrong with my code it’s working on my system but when I submit it show me wrong answer
#include
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int q,c=0;
cin>>q;
int a[q];
for(int i=0;i<q;i++)
{
cin>>a[i];
}
int m=a[i];
for(int i=0;i<q;i++)
{
if(a[i]<m)
{
m=a[i];
}
}for(int j=m;j>0;j–)
{c=0;
for(int i=0;i<q;i++)
{
if(a[i]%j==0)
{
c++;
}
if(c==q)
{ for(int i=0;i<q;i++)
cout<<a[i]/j<<" ";
}
}
if(c==q){
cout<<endl;
break;
}
}
}
}
what is wrong in this my compiler is giving right answer?
step 1: just find highest common factor(HCF) of all the nos
for ex:In the given question for
case 1: no(s) are :4 ,4 => hcf = 4
case 2: 2,3,4 => hcf will be 1
case 3: 3 15 9 6 => hcf will be 3
step 2:
divide each no of each case with hcf
for ex:
case 1: 4,4 => hcf=4 therefore new nos will be 1,1
case 2: 2,3,4 => hcf=1 therefore new nos will be 2,3,4
case 3: 3,15,9,6 => hcf=3 therefore new nos will be 1,5,3,2
you can see code of this question for given link:
https://www.codechef.com/viewsolution/23428055