We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;// function to get gcdintgcd(longinta,longintb){if(b==0){returna;}else{returngcd(b,a%b);}}intmain(){// n,f and temp variable tlongintn,f,t;cin>>n>>f;longintroot=(int)sqrt(f)+1;set<longint>factors,arr;for(longinti=1;i<root;i++){if(f%i==0){factors.insert(i);factors.insert((longint)f/i);}}for(inti=0;i<n;i++){// get value and insert gcd of value and fcin>>t;arr.insert(gcd(t,f));}for(autoi=arr.begin();i!=arr.end();i++){for(autoit=factors.begin();it!=factors.end();it++){if((*i)%(*it)==0){// remove all factors which divides any valuefactors.erase(it);}}}// print remaining factorscout<<factors.size()<<endl;return0;}
Unfriendly Numbers
You are viewing a single comment's thread. Return to all comments →