#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define lll __int128
const ll step = 10, times = 10;
ll mult_mod(ll a,ll b,ll mod)//快速乘
{
ll res=0;
for(;b;b>>=1){
if(b&1) res=(res+a)%mod;
a=(a+a)%mod;
}
return res;
}
ll pow_mod(ll a,ll b,ll mod)//快速幂
{
ll res=1;
a%=mod;
for(;b;b>>=1){
if(b&1)
res=mult_mod(res,a,mod);
a=mult_mod(a,a,mod);
}
return res;
}
ll check(ll a,ll n,ll x,ll t){
ll ret=pow_mod(a,x,n);//费马小定理 a^(p-1)%p==1
ll last=ret;
for(ll i=1;i<=t;i++){//二次检测定理 如果p是一个素数,则x^2%p==1的解为,则x=1或者x=n-1。
ret=mult_mod(ret,ret,n);
if(ret==1&&last!=1&&last!=n-1) return 1;
last=ret;
}
if(ret!=1) return 1;
return 0;
}
ll prime(ll n){
if(n<2)return 0;
if(n==2)return 1;
if((n&1)==0) return 0;
ll x=n-1;
ll t=0;
while((x&1)==0){x>>=1;t++;}
for(ll i=0;i<times;i++){
ll a=rand()%(n-1)+1;
if(check(a,n,x,t)) return 0;
}
return 1;
}
ll f(ll x, ll c, ll p) {return ((lll)x * x % p + c) % p; }
ll gcd(ll a, ll b) {return a % b == 0 ? b : gcd(b, a % b); }
ll pollar_rho(ll p) {
if (!(p&1)) return 2;
bool isfind = false;
ll c, r1, r2, tmp1 = 1, tmp2, res = 0;
while (!isfind) {
c = rand() % (p - 1) + 1;
r1 = r2 = 0;
do {
for (ll i = 1; i <= step; i ++ ) {
r1 = f(r1, c, p);
r2 = f(f(r2, c, p), c, p);
if (r1 == r2 || !(tmp2 = (lll)tmp1 * abs(r2 - r1) % p)) break;
tmp1 = tmp2;
}
res = gcd(tmp1, p);
if (res > 1) isfind = true;
} while(!isfind && r1 != r2);
}
return res;
}
map<ll, ll> mp;
void getFac(ll p) {
if (p == 1) return ;
if (prime(p)) {
mp[p]++;
return ;
}
ll f = pollar_rho(p);
while (p % f == 0) p /= f;
getFac(f);
getFac(p);
}
void jie(ll x){
mp.clear();
getFac(x);
for(pair<ll, ll> p : mp){
ll c = 0;
while(x % p.first == 0){
x /= p.first;
c++;
}
mp[p.first] = c;
}
}
void solve() {
ll n;
cin >> n;
set<ll> st;
for(ll i = 1; i <= n; i++){
ll x;
cin >> x;
jie(x);
ll y = 1;
for(pll p : mp){
ll z = p.fi, c = p.se;
if(c & 1)
y *= (z);
}
st.insert(y);
}
cout << st.size() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
pollar_rho分解质因数
最新推荐文章于 2024-08-13 17:31:17 发布