1 条题解
-
0

#include <cstdio> #include <iostream> #include <cmath> #include <map> using namespace std; const int M = 100005; #define int long long #define pii pair<int,int> #define mp make_pair int read() { int x=0,f=1;char c; while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;} while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();} return x*f; } int n,cnt,ans,vis[M],p[M]; map<pii,int> mp1,mp2; void init(int n) { for(int i=2;i<=n;i++) { if(!vis[i]) p[++cnt]=i; for(int j=1;j<=cnt && i*p[j]<=n;j++) { vis[i*p[j]]=1; if(i%p[j]==0) break; } } } int f(int x) { int c=1; for(int j=1;p[j]<=2200;j++) { int cnt=0; while(x%p[j]==0) x/=p[j],cnt++; if(cnt==2) c*=p[j]; if(cnt==1) c*=p[j]*p[j]; } return c; } signed main() { n=read();init(100000); for(int i=1;i<=n;i++) { int x=read(),c=1; for(int j=1;p[j]<=2200;j++) { int cnt=0; while(x%p[j]==0) x/=p[j],cnt++; cnt%=3; if(cnt==1) c*=p[j]; if(cnt==2) c*=p[j]*p[j]; } int t=sqrt(x); if(x==1) mp1[mp(c,1)]++; else if(x==t*t) mp1[mp(c,t)]++; else if(x>1e5) ans++; else mp2[mp(c,x)]++; } for(auto x:mp1) { int A=x.first.first,B=x.first.second; int C=x.second,D=f(A); if(B==1 && A==1) ans++; //error:A,D may not all in the map if(B==1 && (A<D || !mp1.count(mp(D,1)))) ans+=max(C,mp1[mp(D,1)]); if(B>1) ans+=max(C,mp2[mp(D,B)]),mp2[mp(D,B)]=0; } for(auto &x:mp2) ans+=x.second; printf("%lld\n",ans); }
- 1
信息
- ID
- 8791
- 时间
- 5000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者