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 数学 暴力的更多相关文章

  1. 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. 题解:很显然只有 \( ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. <Math> 29 365

    29. Divide Two Integers class Solution { public int divide(int dividend, int divisor) { if(dividend ...

  2. 基于mysqld_multi实现MySQL 5.7.24多实例多进程配置

    学习环境: 操作系统 IP地址 主机名 软件包 备注 CentOS7.5 192.168.200.111 localhost       实验初始配置:所有主机关闭防火墙与selinux [root@ ...

  3. Python连载51-网络编程基础知识

    一.网络编程 1.网络.网络协议(一套规则) 2.网络模型: (1)七层模型-七层 物理层(比如网线.锚).数据链路层(比如电压电流).网络层.传输层.会话层.表示层.应用层(我们的活动基本都在这一层 ...

  4. Numpy数值类型与数值运算-03

    什么是NumPy? NumPy是Python中科学计算的基本软件包.它是一个Python库,提供多维数组对象,各种派生对象(例如蒙版数组和矩阵) 以及各种例程,用于对数组进行快速操作,包括数学,逻辑, ...

  5. CAS单点登录流程图

    1.cas单点登录原理图 2.cas使用代理服务器流程图 3.cas和spring security集成流程图

  6. 【前端知识体系-NodeJS相关】对于EventLoop(事件轮询)机制你到底了解多少?

    EventLoop 1. EventLoop的执行流程图 ┌───────────────────────┐ ┌─>│ timers │<----- 执行 setTimeout().set ...

  7. Fragment生命周期函数调用(ViewPager切换方式)

    在使用ViewPager时,Google亲爹为我们提供了多种PagerAdapter.其中,与Fragment相关的是FragmentPagerAdapter和FragmentStatePagerAd ...

  8. [笔记] .net core WPF 程序,发布独立程序与单一执行程序

    如何发布独立可运行的,和只有一个文件的 .net core WPF 程序. 1 发布并打包 Step 1 在项目上右键,在菜单中选择发布,使用文件发布,选择独立部署模式,其它的条件,依照自己的情况设置 ...

  9. git 配置远程仓库(同一个邮箱注册多个gitlab仓库)

    之前配置的全局用户和邮箱,如果是多个注册账户就不能设置为全局账户 git config --global user.name "username" git config --glo ...

  10. SpringBoot(五) SpringBoot整合mybatis

    一:项目结构: 二:pom文件如下: <parent> <groupId>org.springframework.boot</groupId> <artifa ...