Anticube

 

5590: Anticube

时间限制: 5 Sec  内存限制: 256 MB
提交: 33  解决: 5
[提交][状态][讨论版][命题人:admin]

题目描述

Snuke got positive integers s1,…,sN from his mother, as a birthday present. There may be duplicate elements.

He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both si and sj(i≠j) are circled, the product sisj is not cubic. For example, when s1=1,s2=1,s3=2,s4=4, it is not possible to circle both s1 and s2 at the same time. It is not possible to circle both s3 and s4 at the same time, either.

Find the maximum number of integers that Snuke can circle.

Constraints
1≤N≤105
1≤si≤1010
All input values are integers.

输入

The input is given from Standard Input in the following format:

N
s1
:
sN

输出

Print the maximum number of integers that Snuke can circle.

样例输入

8
1
2
3
4
5
6
7
8

样例输出

6

提示

Snuke can circle 1,2,3,5,6,7.

来源

AtCoder Grand Contest 003 

【题意】有n个数,从这n个数中选出最多的数,使得两两相乘不是一个立方数。

 

【思路】根据质数唯一分解定理,任何一个数都可以分解成某些质数相乘,对于si来说,可以把其分解成某些质数相乘的形式,并把每个质因数的指数都模3化简成最简形式,现在的任务就变成了求化简后的数的补数(补数*化简后的原数==某数的3次方)。si的范围为10^10次方,所以质因数的范围为10^(10/3),提前对这些素数进行素数打表。

【代码如下】

 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e5+10;
ll a[N],b[N],primes[N];
int n,vis[N],k;
map<ll,int>mp;

void init(){
    k = 0;
    for(ll i = 2; i*i*i <= 1e10; i ++){
        int flag = 0;
       for(int j = 2; j <= i/2; j ++) if(i%j==0){flag=1;break;}
       if(flag==0) primes[k++] = i;
    }
}

ll sqr(ll x){
    return x*x;
}

int main(){
    init();
    scanf("%d",&n);
    for(int i = 1; i <= n; i ++){
        ll x; scanf("%lld",&x);
        for(int j = 0; j < k; j ++){
            ll tmp = primes[j]*primes[j]*primes[j];
            if(tmp > x) break;
            while(x % tmp == 0) x /= tmp;
        }
        mp[x] ++; a[i] = x;
        ll y = 1;
        for(int j = 0; j < k; j ++){
            ll tmp = primes[j]*primes[j]*primes[j];
            if(tmp > x) break;
            if(x % primes[j] == 0){
                y *= (x % (primes[j]*primes[j]) == 0) ? primes[j] : primes[j]*primes[j];
                while(x % primes[j] == 0) x /= primes[j];
            }
        }
        if(sqr((ll)sqrt(x)) == x) y *= (ll)sqrt(x);
        else y *= x*x;
        b[i] = y;
    }
    int ans = 0;
    if(mp[1]) ans ++, mp[1] = 0;
    for(int i = 1; i <= n; i ++){
        ans += max(mp[a[i]],mp[b[i]]); mp[a[i]] = mp[b[i]] = 0;
    }
    printf("%d\n",ans);
    return 0;
}

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值