传送门

要满足存在 $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. Codeforces 23A You're Given a String...

    A. You're Given a String... time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Flask 四种响应类型

    1 直接返回字符串 可以返回状态码 @app.route('/testresponse', methods=['GET', 'POST']) def testresponse(): return &q ...

  3. 关于mysql数据库远程访问

    mysql数据库安装默认为只能本地访问,若需远程连接需根据不同的操作系统做一些操作 Windows: 新装的mysql本地无法登录,显示为1045错误 mysql#1045(1045Access de ...

  4. 史上最详细的C语言和Python的选择排序算法

    未经同意,请勿转载!如有收货,请留一赞,不胜感激! 同时欢迎加入我们的qq交流群:326079727 话不多说上代码: C语言: //选择排序走起 //原理:吃透原理再去实现,选择排序也是类似于冒泡排 ...

  5. Custom Roles Based Access Control (RBAC) in ASP.NET MVC Applications - Part 1 (Framework Introduction)

    https://www.codeproject.com/Articles/875547/Custom-Roles-Based-Access-Control-RBAC-in-ASP-NET Introd ...

  6. 【matlab】模拟变焦拼接代码备份

    1.初版,边缘未处理. % % In----near % If----far % In=imread('D:\文件及下载相关\桌面\模拟变焦拼接\Matlab_code\nearframe\frame ...

  7. kotlin使用中辍标记法调用函数

    fun main(arg: Array<String>) { var str = "hello world" print(str div("l")) ...

  8. windows7安装docker异常:looks like something went wrong in step ‘looking for vboxmanage.exe’

    一.背景 最近准备抽点时间研究下docker,选择在家中的windows系统上安装. 我的系统是windows7,首先安装Docker Toolbox,Docker Toolbox是一个工具集,主要包 ...

  9. scikit-learn机器学习(四)使用决策树做分类

    我们使用决策树来创建一个能屏蔽网页横幅广告的软件. 已知图片的数据判断它属于广告还是文章内容. 数据来自 http://archive.ics.uci.edu/ml/datasets/Internet ...

  10. Spring Security(4):自定义配置

    接着上节的讲,在添加了@EnableWebSecurity注解后,如果需要自定义一些配置,则需要和继承WebSecurityConfigurerAdapter后,覆盖某些方法. 我们来看一下WebSe ...