Jaydeep999997

Untitled

Aug 5th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. typedef long double ld;
  5. typedef pair<int,int> pi;
  6. typedef pair<ll,ll> pll;
  7. #define Max 1000001
  8. #define inf INT_MAX
  9. #define llinf LONG_LONG_MAX
  10. #define rep(i,a,b) for(i=a;i<=b;i++)
  11. #define rrep(i,a,b) for(i=a;i>=b;i--)
  12. #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
  13. #define pb push_back
  14. #define pf push_front
  15. #define F first
  16. #define S second
  17. #define ub upper_bound
  18. #define lb lower_bound
  19. #define all(v) v.begin(),v.end()
  20. #define PI 3.14159265358979311599796346854418516159057617187500
  21. #define endl '\n'
  22. const ll N=1e6+1,mod=1000000007;
  23. ll a[N],fact[11],spf[N]={0},par[N],sz[N];
  24. bool vis[N]={0};
  25. bool isprime[Max] = {false};
  26. set<ll> ms;
  27. void sieve()
  28. {
  29.     int i,j;
  30.     for(i=0;i<Max;i++)
  31.     {
  32.         isprime[i]=true;
  33.     }
  34.     isprime[0]=isprime[1]=true;
  35.     for(i=2;i*i<Max;i++)
  36.     {
  37.         if(isprime[i])
  38.         {
  39.             spf[i]=i;
  40.             for(j=i*i;j<Max;j+=i)
  41.             {
  42.                 if(spf[j]==0)
  43.                 {
  44.                     spf[j]=i;
  45.                 }
  46.                 isprime[j]=false;
  47.             }
  48.         }
  49.     }
  50. }
  51. void initial()
  52. {
  53.     for(int i=0;i<N;i++)
  54.     {
  55.         par[i]=i;
  56.         sz[i]=1;
  57.     }
  58.     fact[0]=1;
  59.     for(int i=1;i<11;i++)
  60.     {
  61.         fact[i]=fact[i-1]*i;
  62.     }
  63.     sieve();
  64. }
  65. ll getp(ll x)
  66. {
  67.     while(par[x]!=x)
  68.     {
  69.         par[x]=par[par[x]];
  70.         x=par[x];
  71.     }
  72.     return x;
  73. }
  74. void merge(ll a,ll b)
  75. {
  76.     ll p1=getp(a),p2=getp(b);
  77.     if(p1!=p2)
  78.     {
  79.         if(sz[p2]>sz[p1])
  80.         {
  81.             swap(p1,p2);
  82.         }
  83.         sz[p1]+=sz[p2];
  84.         par[p2]=p1;
  85.     }
  86. }
  87. void work(ll n)
  88. {
  89.     ll temp=n;
  90.     vector<ll> f;
  91.     while(n>1)
  92.     {
  93.         ll x=spf[n];
  94.         while(n%x==0)
  95.         {
  96.             n/=x;
  97.         }
  98.         ms.insert(x);
  99.         f.pb(x);
  100.     }
  101.     if(n>2)
  102.     {
  103.         f.pb(n);
  104.     }
  105.     for(int i=0;i<(int)f.size()-1;i++)
  106.     {
  107.         merge(f[i],f[i+1]);
  108.     }
  109. }
  110. signed main()
  111. {
  112.     fast;
  113.     ll pro=1,temp,t,m,n,k,i,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
  114.     initial();
  115.     cin>>n;
  116.     rep(i,1,n)
  117.     {
  118.         cin>>a[i];
  119.         work(a[i]);
  120.     }
  121.     for(auto p:ms)
  122.     {
  123.         x=getp(p);
  124.         vis[x]=1;
  125.     }
  126.     cnt=0;
  127.     for(auto p:ms)
  128.     {
  129.         if(vis[p])
  130.         {
  131.             cnt++;
  132.         }
  133.     }
  134.     for(i=1;i<=(cnt/2);i++)
  135.     {
  136.         temp=fact[cnt-i]*fact[i];
  137.         ans+=fact[cnt]/temp;
  138.     }
  139.     cout<<ans<<endl;
  140.     return 0;
  141. }
Add Comment
Please, Sign In to add comment