传送门

要满足存在 $x$ ,使得 $a_i \cdot a_j = x^k$

那么充分必要条件就是 $a_i \cdot a_j$ 质因数分解后每个质因数的次幂都要为 $k$ 的倍数

证明显然

设 $a_i=\sum_{j=1}^{x}p_j^{t_j}$ ,那么不妨变成 $\sum_{j=1}^{x}p_j^{t_j \mod k}$

然后考虑固定 $j$,设 $a_j=\sum_{k=1}^{x}p_k^{t_k}$ ,只要求有多少 $a_i$ 的值为 $\sum_{k=1}^{x}p_k^{k-t_k}$ 即可

用 $map$ 维护一下就行了,具体看代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
int n,K;
int pri[N],fir[N],tot;
bool not_pri[N];
void pre()
{
not_pri[]=; fir[]=;
for(int i=;i<N;i++)
{
if(!not_pri[i]) pri[++tot]=i,fir[i]=i;
for(int j=;j<=tot;j++)
{
ll g=1ll*i*pri[j]; if(g>=N) break;
not_pri[g]=; fir[g]=pri[j];
if(i%pri[j]==) break;
}
}
}
map <ll,int> cnt;
int main()
{
pre();
n=read(),K=read(); ll ans=;
for(int i=;i<=n;i++)
{
int t=read(); vector < pair<int,int> > P;
while(t!=)
{
int &p=fir[t];
if((!P.size())||p!=P.back().first)
P.push_back(make_pair(p,));
else P.back().second++;
t/=p;
}
ll x=,y=; bool GG=;
for(auto d: P)
{
for(int j=;j<=d.second%K;j++)
x*=d.first;
for(int j=;j<=(K-(d.second%K))%K;j++)
{
if(y>=N) { GG=; break; }
y*=d.first;
}
}
if(!GG) ans+=cnt[y]; cnt[x]++;
}
printf("%lld\n",ans);
return ;
}

Codeforces 1247D. Power Products的更多相关文章

  1. [CodeForces - 1225D]Power Products 【数论】 【分解质因数】

    [CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...

  2. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

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

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

  5. Codeforces Round #596 (Div. 2)D.Power Products

    题意: 给一个数组,给你一个k,找出两个数字的积可以变成xk的数对对数 解析: 当且仅当,两个数进行质因子分解后每个因子的个数都是k的倍数个就说明这是满足条件的一对,可以让每个因子个数%k用map找对 ...

  6. CodeForces - 906D Power Tower(欧拉降幂定理)

    Power Tower CodeForces - 906D 题目大意:有N个数字,然后给你q个区间,要你求每一个区间中所有的数字从左到右依次垒起来的次方的幂对m取模之后的数字是多少. 用到一个新知识, ...

  7. [Codeforces]906D Power Tower

    虽说是一道裸题,但还是让小C学到了一点姿势的. Description 给定一个长度为n的数组w,模数m和询问次数q,每次询问给定l,r,求: 对m取模的值. Input 第一行两个整数n,m,表示数 ...

  8. Codeforces 1120D Power Tree [最小生成树]

    洛谷 Codeforces 这题怎么一个中文题解都没有,是不是你们都认为太水了-- 思路 显然可以用dfs序把每个节点变成给一个区间的叶子节点加上某个数. 显然把叶子序列差分一下变为\(a_1,a_2 ...

  9. CodeForces 907F Power Tower(扩展欧拉定理)

    Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is u ...

随机推荐

  1. OpenFOAM 中的边界条件(一)【转载】

    链接:http://xiaopingqiu.github.io/2016/04/02/Boundary-conditions-in-OpenFOAM1/ 本系列解读 OpenFOAM 中边界条件的实现 ...

  2. jboss虚拟机快照

    若使用jboss,则一定要记得隔断时间拍一个快照,这样如果虚拟机坏了,则可以进行回复快照,避免再次花时间去解决问题. 拍快照:启动虚拟机,然后,操作如下. 选择,current State,右击,则可 ...

  3. Airbnb新用户的民宿预定结果预测

    1. 背景 关于这个数据集,在这个挑战中,您将获得一个用户列表以及他们的人口统计数据.web会话记录和一些汇总统计信息.您被要求预测新用户的第一个预订目的地将是哪个国家.这个数据集中的所有用户都来自美 ...

  4. SQLW3School-高级:SQL TOP 子句

    ylbtech-SQLW3School-高级:SQL TOP 子句 1.返回顶部 1. TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是非常有用的 ...

  5. Android-Handler消息机制实现原理)(转)

    Android-Handler消息机制实现原理   一.消息机制流程简介 在应用启动的时候,会执行程序的入口函数main(),main()里面会创建一个Looper对象,然后通过这个Looper对象开 ...

  6. 阿里RDS数据库 全量备份恢复到本地MYSQL

    阿里RDS数据库 全量备份恢复到本地MYSQL   1.首先下载RDS的全量备份 下载完成后上传到服务器备用   2.安装MySQL 5.6 首先删除机上其他的MySQL版本 检查系统是否安装其他版本 ...

  7. QPixmap QImage 相互转化

    QPainter p(this); QPixmap pixmap; pixmap.load("E:\\参考文件\\image\\1.jpg"); //QPixmap->QIm ...

  8. 安装php扩展sphinx-1.2.0.tgz和libsphinxclient0.9.9

    一.首先安装libsphinxclient(php模块需要) cd /usr/local/src/tar zxvf sphinx-0.9.9.tar.gzcd sphinx-0.9.9/api/lib ...

  9. Generate Maximum revenue by selling K tickets from N windows

    Objective: Given ‘N’ windows where each window contains certain number of tickets at each window. Pr ...

  10. 记录下关于RabbitMQ常用知识点(持续更新)

    1.端口及说明: 4369 -- erlang发现口 5672 --client端通信口 15672 -- 管理界面ui端口 25672 -- server间内部通信口 举例说明 我们访问Rabbit ...