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.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn,m;cin>>n>>m;vector<int>a,b;for(inti=0;i<n;++i){intvalue;cin>>value;a.push_back(value);}for(inti=0;i<m;++i){intvalue;cin>>value;b.push_back(value);}intmaxA=*max_element(a.begin(),a.end());intminB=*min_element(b.begin(),b.end());intnumBetweens=0;for(intx=maxA;x<=minB;++x){boolcont=true;for(inti=0;i<n;++i){if(x%a[i]!=0){cont=false;}}if(cont){for(intj=0;j<m;++j){if(b[j]%x!=0){cont=false;}}}if(cont){numBetweens+=1;}}cout<<numBetweens;return0;}
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 →
To be compared to what I found in C++ ;-)