Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力
D. Power Products
You are given n positive integers a1,…,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk.
Input
The first line contains two integers n and k (2≤n≤105, 2≤k≤100).
The second line contains n integers a1,…,an (1≤ai≤105).
Output
Print a single integer — the number of suitable pairs.
Example
input
6 3
1 3 9 8 24 1
output
5
Note
In the sample case, the suitable pairs are:
a1⋅a4=8=23;
a1⋅a6=1=13;
a2⋅a3=27=33;
a3⋅a5=216=63;
a4⋅a6=8=23.
题意
题目这么短,我就偷懒不翻译了吧。。
题解
首先我们质因数分解后,如果两个数的质因数分解后的每个数的因子个数都是k的倍数,那么就说明有解。
于是我们先对每个数质因数分解一下,然后再用一个vector去找一下配对的那一个是哪个。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,k;
int a[maxn];
map<vector<pair<int,int> >,int>H;
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
long long ans = 0;
for(int i=0;i<n;i++){
string tmp="";
vector<pair<int,int> >fac;
for(int now=2;now*now<=a[i];now++){
int number=0;
while(a[i]%now==0){
a[i]/=now;
number+=1;
}
if(number%k)
fac.push_back(make_pair(now,number%k));
}
if(a[i]>1)fac.push_back(make_pair(a[i],1%k));
vector<pair<int,int> >fac2;
for(int j=0;j<fac.size();j++){
fac2.push_back(make_pair(fac[j].first,k-fac[j].second));
}
ans+=H[fac2];
H[fac]++;
}
cout<<ans<<endl;
}
Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力的更多相关文章
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products
链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary
链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is a ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things
链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math te ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) F. Tree Factory 构造题
F. Tree Factory Bytelandian Tree Factory produces trees for all kinds of industrial applications. Yo ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) E. Rock Is Push dp
E. Rock Is Push You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the b ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法
B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things 水题
A. Forgetting Things Kolya is very absent-minded. Today his math teacher asked him to solve a simple ...
随机推荐
- 【转】Java中的关键字 transient
阅读目录 先解释下Java中的对象序列化 关于transient关键字 举个例子 参考资料 先解释下Java中的对象序列化 在讨论transient之前,有必要先搞清楚Java中序列化的含义: Jav ...
- 【STM32H7教程】第26章 STM32H7的TCM,SRAM等五块内存的超方便使用方式
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第26章 STM32H7的TCM,SRAM等五块 ...
- pixijs shader 案例
pixijs shader 案例 const app = new PIXI.Application({ transparent: true }); document.body.appendChild( ...
- WildFly16.0配置数据源并测试
目前网络上罕有近期版本的配置,本人经多次尝试网络中不同方式配置,在Testing Connection一步中尽皆失败后,查询官方文档未果,摸索出一条可行之路,在此分享于诸位朋友. [../wildfl ...
- jQuery 源码分析(十九) DOM遍历模块详解
jQuery的DOM遍历模块对DOM模型的原生属性parentNode.childNodes.firstChild.lastChild.previousSibling.nextSibling进行了封装 ...
- sql慢查询工具(配置代码)
# 在mysql的配置文件/etc/mysql/mysql.conf.d/mysqld.cnf[mysqld]中配置懒查询 slow_query_log = ON # 是否已经开启慢查询 long_q ...
- Python爬取620首虾米歌曲,揭秘五月天为什么狂吸粉?!
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: CDA数据分析师 PS:如有需要Python学习资料的小伙伴可以加点 ...
- Linux常用命令(2)
3.帮助命令 A,帮助命令:man B,其他帮助命令 3.1,格式:man [命令名] 查看命令拥有哪个级别的帮助: ...
- Python【day 17】面向对象-成员
类的变量分成2种: 1.成员变量 概念:在构造方法中的变量,前面带有self 作用:可以在类中不同的方法间使用 2.类变量-静态变量 概念:在类中,构造方法和普通方法之外,定义的变量 作用: 1.调用 ...
- LooseVersion()使用及.__version__版本号的获取
我简单看了distutils库,但发现目前还用不到,感觉有些复杂.因此我简单复制了别人的介绍,如下: Distutils可以用来在Python环境中构建和安装额外的模块.新的模块可以是纯Python的 ...