可爱捏
可爱捏
题意
给出
求最多选出多少个数,使她们两两的乘积不为完全立方数。
思路
可以先将
由此可知对于每个数,和她相乘等于完全立方数的数是唯一确定的。
如果我们能求出指数
发现每对数之间互相独立,只需要选择数量多的一个即可。
但
由于我们求的是指数
我们只需要暴力求出小于等于
记
我们发现
若
分类讨论:
-
; -
由两个相同质数组成; -
由一个或两个不同质数组成。
乘上对应的数即可。
时间复杂度:
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, s[N], ans;
map <int, int> cnt, ne;
set <int> used;
vector <int> _;
signed main() {
freopen("lovely.in", "r", stdin);
freopen("lovely.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++) cin >> s[i];
for (int i = 1, c; i <= n; i ++) {
int x = 1, y = 1, t = s[i]; // x;指数 mod 3 后的数 y:x对应的数
for (int j = 2; j * j * j <= s[i]; j ++) { // 暴力分解
for (c = 0; t % j == 0; t /= j, c = (c + 1) % 3);
for (int k = 1; c && k <= c; k ++) x *= j;
for (int k = 1; c && k <= 3 - c; k ++) y *= j;
}
if ((int)sqrt(t) * (int)sqrt(t) == t) y *= sqrt(t); // 分类讨论
else y *= t * t;
x *= t, cnt[x] ++, ne[x] = y, _.push_back(x);
}
for (auto x : _) {
if (x == 1) continue;
if (used.count(x) || used.count(ne[x])) continue;
ans += max(cnt[x], cnt[ne[x]]); // x 和 x 对应的数只能取一个 个数较大的
used.insert(x); used.insert(ne[x]);
}
cout << ans + (cnt[1] > 0) << "\n";
return 0;
}
本文来自博客园,作者:maniubi,转载请注明原文链接:https://www.cnblogs.com/maniubi/p/18548230,orz
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】