传送门

要满足存在 $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. CF1208B

    CF1208B 题意: 给出n个数字,找出最小的一端连续区间进行删除操作,使其剩余元素不含重复元素,求要删除的最小区间长度 解法: 删除子段后,前缀和后缀保持不变,可能长度为0.让我们修复不包含任何重 ...

  2. 解决IntelliJ无法导入maven包的问题

    使用如下的pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  3. 常见Web攻击及解决方案

    DoS和DDoS攻击 DoS(Denial of Service),即拒绝服务,造成远程服务器拒绝服务的行为被称为DoS攻击.其目的是使计算机或网络无法提供正常的服务.最常见的DoS攻击有计算机网络带 ...

  4. javascript-类型、值和变量

    基本类型和引用类型 MDN-JavaScript 数据类型和数据结构 ECMAScript 变量可能包含两种不同数据类型的值:基本类型值和引用类型值.基本类型值指的是 简单的数据段,而引用类型值指那些 ...

  5. Gevent模块

    前言 如何在使用1个线程的前提下,提网站的并发性,使用协程? 如果要使用协程首先要解决2个问题: 1.如何检测到代码中遇到了IO操作?(XX) 2.如何在线程代码里上下切换?(Greelet模块) 而 ...

  6. 断句:Store all parameters but the first passed to this function as an array

    // Store all parameters but the first passed to this function as an array //除了第一个参数,把调用publish函数时的所有 ...

  7. c++ new bad_alloc

    try { for (int i = 0; i<1000; i++) { test1 = new Test(); cout << i << " new dog ...

  8. 14 Flutter仿京东商城项目 头部搜索导航布局 修改主题 修正ScreenAdapter类

    main.dart import 'package:flutter/material.dart'; import 'routes/router.dart'; void main() => run ...

  9. Qt编写自定义控件27-颜色按钮面板

    一.前言 颜色按钮面板主要用在提供一个颜色按钮面板,用户单击某个按钮,然后拿到对应的颜色值,用户可以预先设定常用的颜色集合,传入到控件中,自动生成面板颜色集合按钮,每当滑过按钮的时候,按钮边缘高亮提示 ...

  10. ansible实践

    ansible常用module ansible-doc -l List available modules -s Show playbook snippet for specified module( ...