We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int gcd(int,int);
int lcm(int,int);
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b)
{
return (a*b)/gcd(a,b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0 ; ia[i])
printf("%d ",lcm(a[i+1],a[i]));
else
printf("%d ",lcm(a[i],a[i+1]));
}
printf("%d\n",a[n-1]);
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
John and GCD list
You are viewing a single comment's thread. Return to all comments →
include
int gcd(int,int); int lcm(int,int); int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return (a*b)/gcd(a,b); } int main() { int t; scanf("%d",&t); while(t--) { int n,i; scanf("%d",&n); int a[n]; for(i=0 ; ia[i]) printf("%d ",lcm(a[i+1],a[i])); else printf("%d ",lcm(a[i],a[i+1])); } printf("%d\n",a[n-1]);
} return 0; }