Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- typedef long double ld;
- typedef pair<int,int> pi;
- typedef pair<ll,ll> pll;
- #define Max 1000001
- #define inf INT_MAX
- #define llinf LONG_LONG_MAX
- #define rep(i,a,b) for(i=a;i<=b;i++)
- #define rrep(i,a,b) for(i=a;i>=b;i--)
- #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
- #define pb push_back
- #define pf push_front
- #define F first
- #define S second
- #define ub upper_bound
- #define lb lower_bound
- #define all(v) v.begin(),v.end()
- #define PI 3.14159265358979311599796346854418516159057617187500
- #define endl '\n'
- const ll N=1e6+1,mod=1000000007;
- ll a[N],fact[11],spf[N]={0},par[N],sz[N];
- bool vis[N]={0};
- bool isprime[Max] = {false};
- set<ll> ms;
- void sieve()
- {
- int i,j;
- for(i=0;i<Max;i++)
- {
- isprime[i]=true;
- }
- isprime[0]=isprime[1]=true;
- for(i=2;i*i<Max;i++)
- {
- if(isprime[i])
- {
- spf[i]=i;
- for(j=i*i;j<Max;j+=i)
- {
- if(spf[j]==0)
- {
- spf[j]=i;
- }
- isprime[j]=false;
- }
- }
- }
- }
- void initial()
- {
- for(int i=0;i<N;i++)
- {
- par[i]=i;
- sz[i]=1;
- }
- fact[0]=1;
- for(int i=1;i<11;i++)
- {
- fact[i]=fact[i-1]*i;
- }
- sieve();
- }
- ll getp(ll x)
- {
- while(par[x]!=x)
- {
- par[x]=par[par[x]];
- x=par[x];
- }
- return x;
- }
- void merge(ll a,ll b)
- {
- ll p1=getp(a),p2=getp(b);
- if(p1!=p2)
- {
- if(sz[p2]>sz[p1])
- {
- swap(p1,p2);
- }
- sz[p1]+=sz[p2];
- par[p2]=p1;
- }
- }
- void work(ll n)
- {
- ll temp=n;
- vector<ll> f;
- while(n>1)
- {
- ll x=spf[n];
- while(n%x==0)
- {
- n/=x;
- }
- ms.insert(x);
- f.pb(x);
- }
- if(n>2)
- {
- f.pb(n);
- }
- for(int i=0;i<(int)f.size()-1;i++)
- {
- merge(f[i],f[i+1]);
- }
- }
- signed main()
- {
- fast;
- 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;
- initial();
- cin>>n;
- rep(i,1,n)
- {
- cin>>a[i];
- work(a[i]);
- }
- for(auto p:ms)
- {
- x=getp(p);
- vis[x]=1;
- }
- cnt=0;
- for(auto p:ms)
- {
- if(vis[p])
- {
- cnt++;
- }
- }
- for(i=1;i<=(cnt/2);i++)
- {
- temp=fact[cnt-i]*fact[i];
- ans+=fact[cnt]/temp;
- }
- cout<<ans<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment