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 ...
随机推荐
- "中国东信杯"广西大学第二届程序设计竞赛E Antinomy与红玉海(二分)
题目大意: n个人,每个人想参加a[i]轮游戏,但每场游戏必须有个一个人当工具人 问最少有几场游戏 题解: 二分 答案范围:[0,sigma a[i]] check:首先a[i]>=ans,其次 ...
- 自己收集的好玩的JS特效(持续更新)
放到我自己的服务器上了. 网 scale.html 樱花 sakura.html
- Codechef October Challenge 2019 Division 1
Preface 这次CC难度较上两场升高了许多,后面两题都只能借着曲明姐姐和jz姐姐的仙气来做 值得一提的是原来的F大概需要大力分类讨论,结果我写了一大半题目就因为原题被ban了233 最后勉强涨了近 ...
- Note | 北航《网络安全》复习笔记
目录 1. 引言 2. 计算机网络基础 基础知识 考点 3. Internet协议的安全性 基础知识 考点 4. 单钥密码体制 基础知识 考点 5. 双钥密码体制 基础知识 考点 6. 消息认证与杂凑 ...
- python解释器和环境安装
现在最新的是python3.7下载好安装包:python-3.7.0-amd64.exe下载地址:https://www.python.org/getit/ 选择3.7.0下载 选择一款适合自己的编译 ...
- (四)初识NumPy(函数和图像的数组表示)
本章节主要介绍NumPy中的三个主要的函数,分别是随机函数.统计函数和梯度函数,以及一个较经典的用数组来表示图像的栗子!,希望大家能有新的收货,共同进步! 一.np.random的随机函数(1) ra ...
- 如何在GibHub上传自己的项目
如何上传项目至GinHub 准备好项目.在项目ssm-crud的目录下右击,点击Git Bash Here,打开git命令行. 在命令行中,输入git init,使项目文件夹加入git管理: 输入gi ...
- vue-商品管理案例改进
案例改进 vue-resource全局配置: Vue.http.options.root = 'http://vue.studyit.io/'; 全局启用 emulateJSON 选项 Vue.htt ...
- liunx简单命令
mysql -h主机地址 -u用户名 -p用户密码 --进入数据库1.显示数据库列表. show databases; 2.显示库中的数据表: use mysql: //打开库 show tables ...
- idea的service注入mapper报错
一.问题 idea的java项目中,service类中注入mapper报错 二.解决 方法1 在mapper类上加上 @Repository 注解即可,当然不加也行,程序也不回报错,是idea的误报 ...