Sort by

recency

|

3022 Discussions

|

  • + 0 comments

    int getTotalX(vector a, vector b) { vector lcm = {}; vector hcf = {};

    int start_point = *max_element(a.begin(), a.end());
    int end_point = *min_element(b.begin(), b.end());
    for (int i = start_point; i <= end_point; i++)
        {
        bool a_flag = true;
        bool b_flag = true;
        for (int a_temp : a)
            {
            if (i%a_temp != 0)
                {
                a_flag = false;
                break;
                }
            }
        if (a_flag)
            {
            lcm.push_back(i);
            }
        for (int b_temp : b)
            {
            if (b_temp%i != 0)
                {
                b_flag = false;
                break;
                }
            }
        if (b_flag)
            {
            hcf.push_back(i);
            }
        }
    vector<int> res;
    set_intersection(lcm.begin(), lcm.end(), hcf.begin(), hcf.end(), back_inserter(res));
    return res.size();
    

    }

  • + 0 comments
    public static int getTotalX(List<Integer> a, List<Integer> b) {
        // Write your code here
        int first = a.get(a.size()-1), end = b.get(0);
        int count = 0;
        for(int start = first ; start<=end ; start += first){
          boolean status = true;
          for(int num : a){
            if(num>start || start%num!=0){
              status = false;
              break;
            }
          }
            if(status){
              for(int val : b){
                if(val<start || val%start!=0){
                  status = false;
                  break;
                }
              }
              if(status) count++;
            }
        }
        return count;
        }
    
    }
    
  • + 0 comments
    input();
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    ans=0
    for i in range(1, 101):
        if all(i%x==0 for x in a) and all(x%i==0 for x in b):
            ans+=1
    print(ans)
    
  • + 0 comments

    Here is my c++ solution, you can see the explanation here : https://youtu.be/Xgchif6uHDU

    #include <bits/stdc++.h>
    
    using namespace std;
    
    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 n, m, e, l = 1, g = 0;
        cin >> n >> m;
        for(int i = 0; i < n; i++){
            cin >> e;
            l = lcm(l, e);
        }
        for(int i = 0; i < m; i++){
            cin >> e;
            g = gcd(g, e);
        }
        int res = 0;
        for(int c = l; c <= g; c+=l)if(g % c == 0) res ++;
        cout << res;
        return 0;
    }
    
  • + 0 comments
    public static int getTotalX(List<int> a, List<int> b)
        {
        
            List<int> GetFactoresMutuos()
            {
                var max = b.Min(x => x);
                List<int> factores = new List<int>();
                for (int i = 1; i <= max; i++)
                {
                    if(b.All(el => el % i == 0))
                        factores.Add(i);
                }
    
                return factores;
            }
    
            List<int> GetPossiveisR(List<int> factoresParaTestar)
            {
                return factoresParaTestar.Where(f => a.All(elA => f % elA == 0)).ToList() ;
            }
    
            var fatores = GetFactoresMutuos();
            var possivesR = GetPossiveisR(fatores);
    
            return possivesR.Count();
        }