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