Sort by

recency

|

3075 Discussions

|

  • + 0 comments
    int getTotalX(vector<int> a, vector<int> b) {
        // assume vectors are sorted and a_n <= b_1    
        int betweenCount = 0;
        
        for (int q = a.back(); q <= b.front(); q += a.back()) {
            bool isMultiple = std::all_of(a.begin(), a.end(),
                [q] (int el) { return q % el == 0; }); 
            bool isFactor = std::all_of(b.begin(), b.end(),
                [q] (int el) { return el % q == 0; });
            if (isMultiple && isFactor)
                betweenCount++;
        }
        
        return betweenCount;
    }
    
  • + 0 comments

    I’ve been exploring different problem-solving approaches lately, and just like finding the right logic in coding challenges, sometimes you also need the right experience in real life to enjoy things fully. For anyone planning an adventure, I recommend checking out The Dune Buggy Dubai Website – it’s a great place to discover thrilling dune buggy rides in the Dubai desert.

  • + 0 comments

    ruby

    def getTotalX(a, b)
      answer_a = a.reduce(:lcm)
      answer_b = b.reduce(:gcd)
    
      (a.max..b.min).count { |n| n % answer_a == 0 && answer_b % n == 0}
    end
    
  • + 0 comments

    **Java Solution **

    public static int getTotalX(List<Integer> a, List<Integer> b) {
    
        /* Assuming the last value in 'a' is the maximum and
           the first value in 'b' is the minimum */
    
        int start = a.get(a.size()-1),end=b.get(0),count=0;
    
                for (int i = start; i <= end; i+=start) { 
    
                    boolean trueForA = true, trueForB = true ;
    
                    for (int num : a) {
                        if (i % num != 0) {
                            trueForA = false;
                            break;
                        }
                    }
    
                    for (int num : b) {
                        if(trueForA)
                            if (num % i != 0) {
                            trueForB = false;
                            break;
                        }
                      }
    
    
                    if (trueForA &&  trueForB) {
                       count++;
                     }
             }
        return count;
    }
    
  • + 0 comments

    THIS IS PYTHON CODE:

    import math
    import os
    import random
    import re
    import sys
    from functools import reduce
    
    def lcm(x, y):
        return x * y // math.gcd(x, y)
    
    def getTotalX(a, b):
        l = reduce(lcm, a)
        g = reduce(math.gcd, b)
        count = 0
        for i in range(l, g + 1, l):
            if g % i == 0:
                count += 1
        return count
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        first_multiple_input = input().rstrip().split()
        n = int(first_multiple_input[0])
        m = int(first_multiple_input[1])
    
        arr = list(map(int, input().rstrip().split()))
        brr = list(map(int, input().rstrip().split()))
    
        total = getTotalX(arr, brr)
    
        fptr.write(str(total) + '\n')
        fptr.close()