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 a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
int lcm(int x, int y )
{
if(x==0)
return 0;
return (x*y)/gcd(x,y);
}
int main()
{
int n,m;
cin>>n>>m;
int a[n],b[m];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int j=0; j<m; j++)
{
cin>>b[j];
}
int x=a[0];
int y=b[0];
for(int i=0; i<n; i++)
{
x=lcm(x,a[i]);
}
for(int j=0; j<m; j++)
{
y=gcd(y,b[j]);
}
//cout<<x<<endl;
//cout<<y<<endl;
//count the multiples of lcm of a that divides gcd of b
int k=1;
int count=0;
int num=x;
while(x<=y)
{
if(y%(x)==0) count++;
k++;
x=num*k;
}
cout<
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
include
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int lcm(int x, int y ) {
}
int main() { int n,m; cin>>n>>m; int a[n],b[m];
cout<