传送门

要满足存在 $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. vfork与fork的区别

    vfork()用法与fork()相似,但是也有区别,具体区别归结为以下3点: 1. fork():子进程拷贝父进程的数据段,代码段.vfork():子进程与父进程共享数据段. 2. fork():父子 ...

  2. IDEA 重复代码快速重构(抽取重复代码快捷键)

    Ctrl+Alt+M 顺带一提,eclipse的快捷键是:Alt+Shift+M;

  3. DELPHI安卓定位权限申请

    DELPHI安卓定位权限申请 安卓8及以后版本的权限分为静态和动态申请2部分,而之前的安卓版本只需要静态申请权限. 1)静态申请定位权限: 2)动态申请定位权限: uses System.Permis ...

  4. python爬虫简单实现,并在java中调用python脚本,将数据保存在json文件中

    # coding:utf-8 import urllib2 from bs4 import BeautifulSoup import json import sys reload(sys) sys.s ...

  5. iOS获取应用当前Caches目录路径以及当前日期

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSSt ...

  6. Markdown 图片的简单处理

    0. 前言 最近写 md 文章的时候发现,在 markdown 里插入一些很长的图片的时候,会显得很不好看,于是去查了一下如何实现 markdown 里图片的并排显示,参考了各个博客内的内容和 mar ...

  7. CentOS下yum安装mysql

    其实跟windows下安装过程差别不大,就是下载为了方便使用了yum的方式.安装前先确认下系统是否还安装mysql,卸载是否不完全,再去官网(http://dev.mysql.com/download ...

  8. <c:if test="${uns ne ‘admin’}">

    类别 运算符 算术运算符 + . - . * . / (或 div )和 % (或 mod ) 关系运算符 == (或 eq ). != (或 ne ). < (或 lt ). > (或 ...

  9. scikit-learn机器学习(一)简单线性回归

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt ## 设置字符集,防止中文乱码 import ma ...

  10. 【leetcode_easy】530. Minimum Absolute Difference in BST

    problem 530. Minimum Absolute Difference in BST 参考 1. Leetcode_easy_530. Minimum Absolute Difference ...