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<bits/stdc++.h>#include<algorithm>#define ll long longusingnamespacestd;stringltrim(conststring&);stringrtrim(conststring&);vector<string>split(conststring&);/* * Complete the 'getTotalX' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER_ARRAY a * 2. INTEGER_ARRAY b */intgetTotalX(vector<int>a,vector<int>b){//First find LCM of all the numbers of vector a://Then find all factors of LCM of vector a till 100;//Then iterate through the vector b and check if a factor divides all the numbers //of vector b then count increment!!!lln=a.size(),m=b.size();intres=a[0];llprod=1;for(autoit:a){prod*=it;}for(inti=1;i<n;i++){res=__gcd(res,a[i]);}llLCM=prod/res;vector<ll>lc;for(inti=1;i<101;i++){lc.push_back(LCM*i);}intcount=0;for(inti=0;i<lc.size();i++){boolisfactor=true;for(intj=0;j<m;j++){if((b[j]%lc[i])!=0){isfactor=false;break;}}if(isfactor==true){count++;}}returncount;}
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 →
Can anyone tell me where am I going wrong