Problem Statement

Snuke got positive integers $s_1,...,s_N$ 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 $s_i$ and $s_j (i ≠ j)$ are circled, the product $s_is_j$ is not cubic. For example, when $s_1=1,s_2=1,s_3=2,s_4=4$, it is not possible to circle both $s_1$ and $s_2$ at the same time. It is not possible to circle both $s_3$ and $s_4$ at the same time, either.

Find the maximum number of integers that Snuke can circle.

Constraints

  • $1 ≦ N ≦ 10^5$
  • $1 ≦ s_i ≦ 10^{10}$
  • All input values are integers.

首先 Pollard-Pho 分解质因数(bushi

然后考虑把 \(x\) 每一个因数的指数 \(\bmod 3\) 后出来一个数 \(f(x)\)。那么在这个问题中,若 \(f(x)=f(y)\) ,那么 \(x\) 和 \(y\) 本质是相同的,看做一个等价类。

同时可以发现,把所有指数给取反后,出来一个 \(g(x)\),那么 \(g(x)\) 代表的等价类和 \(f(x)\) 中的数不能同时出现。

这样就很好统计了。

然后你真的想用 Pollar-Pho 吗?

对于 \(x\) 的某一个超过 \(\sqrt[3]{n}\) 质因数,他的指数不会超过 \(3\),所以容易算出 \(f(x)\)

在计算 \(g(x)\) 的时候,把所有在 \(\sqrt[3]{n}\) 之内的因数筛完之后,假设出来是 \(d\),那么如果 \(d=x^2\),\(g(x)\) 乘上 \(\sqrt{d}\),否则如果 \(d\le 1000000\),\(g(x)\) 乘上 \(d^2\),否则 \(g(x)\) 一定超过 \(10^{12}\),不用管。

using namespace std;
typedef long long LL;
const int N=1e5+5;
int n,ans;
LL s;
LL read()
{
LL s=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
s=s*10+ch-48,ch=getchar();
return s;
}
map<LL,LL>to,mp;
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
s=read();
LL v=1,g=1;
for(int j=2;j<=2200;j++)
{
if(s%j==0)
{
int c=0;
while(s%j==0)
s/=j,++c;
c%=3;
if(c==1)
v*=1LL*j*j,g*=j;
else if(c)
v*=j,g*=1LL*j*j;
}
}
g*=s;
mp[g]++;
int k=sqrt(s);
if(1LL*k*k==s)
v*=k,to[g]=v;
else if(s<=1000000)
v*=1LL*s*s,to[g]=v;
}
for(map<LL,LL>::iterator it=mp.begin();it!=mp.end();it++)
{
LL x=(*it).first;
if(x==1)
ans++;
else
ans+=max(mp[x],to.find(x)!=to.end()&&mp.find(to[x])!=mp.end()? mp[to[x]]:0);
mp[x]=mp[to[x]]=0;
}
printf("%d",ans);
}

[AGC003D] Anticube的更多相关文章

  1. AtCoder刷题记录

    构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...

  2. 【agc003D】Anticube

    Portal --> agc003D Description 给你\(n\)个数,要从里面选出最多的数满足这些选出来的数中任意两个数的乘积都不是立方数 Solution (为什么感觉最近这种解法 ...

  3. Agc003_D AntiCube

    传送门 题目大意 给定$N$个数,求一个最大的子集,使得任意两两的乘积不是一个完全立方数. $n\leq 10^5 A_i\leq 10^{10}$ 题解 考虑两两乘积为$x^3$,由于$x^3\le ...

  4. AtCoder Grand Contest 003 D - Anticube

    题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_d 题目大意: 给定\(n\)个数\(s_i\),要求从中选出尽可能多的数,满足任意两个数之积 ...

  5. AT2004 Anticube

    https://www.zybuluo.com/ysner/note/1304774 题面 给定\(n\)个数\(s_i\),要求从中选出最多的数,满足任意两个数之积都不是完全立方数. \(n\leq ...

  6. AtCoderAGC003D Anticube

    Description: 给定一个序列\(a\),要求选出最多的序列元素并保证两两元素的乘积不为立方数 Solution: 我们考虑哪些因子是有用的,如果一个因子的指数\(>3\),我们可以将他 ...

  7. Solution -「AGC 003D」「AT 2004」Anticube

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个数 \(a_i\),要求从中选出最多的数,满足任意两个数之积都不是完全立方数.   \(n\le10^5\) ...

  8. AtCoder Grand Contest 1~10 做题小记

    原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-Grand-Contest-from-1-to-10.html 考虑到博客内容较多,编辑不方便的情 ...

  9. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  10. AtCoder Grand Contest 003

    AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. ...

随机推荐

  1. Docker下elasticsearch8部署、扩容、基本操作实战(含kibana)

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇记录了用docker搭建ElasticS ...

  2. ETL之apache hop系列3-hop Server环境部署与客户端发布管道工作流

    前言 该文档主要是apache hop 2.5的 Windows 10和Linux docker环境部署和客户端发布工作流和管道的相关内容 不使用Docker直接使用应用程序包,下载压缩包文件后,需要 ...

  3. Python隔离环境的搭建

    在nodejs中,我们可以指定扩展安装的路径,那么在python中,我们是不是也可以这么做呢? 当然可以,我们只需要安装一个扩展virtualenv或者virtual wrapper就可以实现环境的隔 ...

  4. 解读Redis常见命令

    Redis数据结构介绍 Redis是一个key-value的数据库,key一般是String类型,不过value的类型多种多样: 贴心小建议:命令不要死记,学会查询就好啦 Redis为了方便我们学习, ...

  5. 局域网内文件分享的简单方式:python - http.server

    在局域网条件下,利用Python自带的HTTP服务功能提供文件共享服务是相对比较简单便捷的方式之一. 一.现实需求及前提条件 1. 文件的服务端(文件分享者)与接收端(文件接收者)在一个局域网,接收端 ...

  6. Solution -「GXOI / GZOI 2019」AND OR Sum

    Description Link. 给定一个 \(N \times N\) 的矩阵,她希望求出: 该矩阵的所有子矩阵的 \(\texttt{AND}\) 值之和(所有子矩阵 \(\texttt{AND ...

  7. Spring Boot 目录遍历--表达式注入--代码执行--(CVE-2021-21234)&&(CVE-2022-22963)&&(CVE-2022-22947)&&(CVE-2022-2296)

    Spring Boot 目录遍历--表达式注入--代码执行--(CVE-2021-21234)&&(CVE-2022-22963)&&(CVE-2022-22947)& ...

  8. Markdown 包含其他文件静态渲染工具

    1. 前言 在 GitHub 上写文档,很多时候要插入 uml,像 mermaid 这种可以直接在 GitHub/GitLab 中渲染的一般直接写个 code block 进去,但是这样造成一个问题就 ...

  9. 安装OpenStack的yum源

    # yum install https://buildlogs.centos.org/centos/7/cloud/x86_64/openstack-liberty/centos-release-op ...

  10. Newstar CTF 2023

    WEEK1 PWN 1.ezshellcode 直接sendline(shellcode)即可 exp: from pwn import * p = remote("node4.buuoj. ...