Sort by

recency

|

3040 Discussions

|

  • + 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

    A Between Two Sets Unit Conversion Calculator is a tool designed to convert units between two different measurement systems, making it easier to compare values across various standards. The key challenge in such a calculator is ensuring accuracy in unit conversions while maintaining efficiency in computation. To solve this issue, the calculator should include a well-structured database of unit conversions through none of us clothing tracksuit, covering different categories such as length, weight, volume, and time. It should also feature an intuitive user interface that allows users to input values in one unit and obtain results in another seamlessly.

  • + 0 comments
    def getTotalX(a, b):
        # Write your code here
        
        ans = 0
        
        max_num = max(a)
        min_num = min(b)
        
        for i in range(max_num, min_num + 1):
            
            count1 = 0
            count2 = 0
            
            for j in a:
                if i % j == 0:
                    count1 += 1
                    
            for k in b:
                if k % i == 0:
                    count2 += 1
                    
            if (count1 == len(a)) and (count2 == len(b)):
                ans += 1
                
        return ans
     
    
  • + 0 comments

    PHP one more

    function getTotalX(array $a, array $b):int {
        $res=0;
        for($i=end($a);$i<=$b[0];$i++) {
            $count1=0;
            $count2=0;
            for($j=0;$j<count($a);$j++){   
                $i % $a[$j] === 0 ? $count1++ : '';
            }
    
            for($j=0;$j<count($b);$j++){
                $b[$j] % $i == 0 ? $count2++ : '';
            }
            
            if($count1 == count($a) && $count2 == count($b)) {
                $res++;
            }
        }
        return $res;
    }
    
  • + 1 comment

    C# solution

    public static int getTotalX(List<int> a, List<int> b)
        {
            List<int> commonDivisors = new List<int>();
            List<int> results = new List<int>();
            
            int divisor = a.Max();
                   
            bool rightDigit = new bool();
            
            while(divisor <= b.Min())
            {
                rightDigit = true;
                
                foreach(int x in a)
                {
                    if(divisor%x != 0){rightDigit = false;break;}
                }
                
                if(rightDigit) commonDivisors.Add(divisor);
                
                divisor++;
            }
            
            foreach(int commonDivisor in commonDivisors)
            {
                rightDigit = true;
                
                if(commonDivisor <= b.Min())
                {
                    foreach(int x in b)
                    {
                            if(x%commonDivisor != 0){rightDigit = false;break;}
                    }
                }
                
                if(rightDigit) results.Add(commonDivisor);
            }
            
            return results.Count;
        }