• + 2 comments
    #include <bits/stdc++.h>
    using namespace std;
    
    // function to get gcd
    int gcd(long int a, long int b){
        if(b==0){
            return a;
        }else{
            return gcd(b, a%b);
        }
    }
    
    int main(){
    // n,f and temp variable t
        long int n, f, t;
        cin>>n>>f;
        long int root = (int)sqrt(f)+1;
        set<long int> factors, arr;
        for(long int i=1; i<root; i++){
            if(f%i==0){
                factors.insert(i);
                factors.insert((long int)f/i);
            }
        }
    
        for(int i=0; i<n; i++){
    		// get value and insert gcd of value and f
            cin>>t;
            arr.insert(gcd(t, f));
        }
    
        for(auto i=arr.begin(); i!=arr.end(); i++){
            for(auto it=factors.begin(); it!=factors.end(); it++){
                if((*i)%(*it)==0){
    						// remove all factors which divides any value
                    factors.erase(it);
                }
            }
        }
    		// print remaining factors
        cout<<factors.size()<<endl;
        return 0;
    }