Codeforces Round #596 (Div. 2)D.Power Products
题意:
给一个数组,给你一个k,找出两个数字的积可以变成xk的数对对数
解析:
当且仅当,两个数进行质因子分解后每个因子的个数都是k的倍数个就说明这是满足条件的一对,可以让每个因子个数%k用map找对应的数。
代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map> using namespace std; typedef long long LL; const int mod=1e9+;
const int maxn=1e5+; int n,k; struct node{
int x,num;
node(){}
node(int _x,int _num):x(_x),num(_num){}
bool operator<(const node &s)const{
if(x!=s.x)return x<s.x;
else return num<s.num;
}
}; vector<node>nodes;
map<vector<node>,int>mp; void f(int x){
int o=;
for(int i=;i<=x/i;i++){
if(x%i==){
int num=;
while(x%i==){
num++;
x/=i;
}
if(num%k!=){
o=;
nodes.push_back(node(i,num%k));
}
}
}
if(x!=)nodes.push_back(node(x,));
if((int)nodes.size()==&&(o==||x==)){
//nodes.push_back(node(x,1));
}
} int main(){
scanf("%d%d",&n,&k);
long long num=;
for(int i=;i<n;i++){
int x;
scanf("%d",&x);
nodes.clear();
f(x);
for(int i=;i<(int)nodes.size();i++){
nodes[i].num=k-nodes[i].num;
}
if(mp[nodes]!=){
num+=mp[nodes];
}
for(int i=;i<(int)nodes.size();i++){
nodes[i].num=k-nodes[i].num;
//printf("%d %d\n",nodes[i].x,nodes[i].num);
}
mp[nodes]++;
//printf("%d %lld\n",i,num);
}
printf("%lld\n",num);
return ;
}
Codeforces Round #596 (Div. 2)D.Power Products的更多相关文章
- 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. 题解:很显然只有 \( ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary 水题
C. p-binary Vasya will fancy any number as long as it is an integer power of two. Petya, on the othe ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 1Python学习CentOS 7 Linux环境搭建
鉴于python3目前已成流行之势,而各发行版Linux依然是自带python2.x,笔者尝试在centos7下,部署Python3.x与2.x共存环境 本文参考博主良哥95网址https://blo ...
- P1058 立体图
链接:Miku ------------------------------ 蒟蒻在线%lmk,ljx,lpy,yyq大佬们 ------------------------------ Good N ...
- STM32存储器映射和寄存器映射
存储器映射 对于Cortex-M3来讲,有一块4G大小的存储器空间.存储器映射指的是芯片厂商为这个空间分配地址的操作.这4G空间被均匀地划分为8个大小为512MB的存储块(block),并且每个块都各 ...
- 广度优先搜索BFS---求出矩阵中“块”的个数
题目: 给出一个 m x n 的矩阵,矩阵中的元素为0或1.如果矩阵中有若干个 1是相邻的,那么称这些1构成了一个“块”.求给定的矩阵中“块”的个数. 0 1 1 1 0 0 1 0 0 1 0 0 ...
- 实验一Git代码版本管理
GIT代码版本管理 实验目的: 1)了解分布式分布式版本控制系统的核心机理: 2) 熟练掌握git的基本指令和分支管理指令: 实验内容: 1)安装git 2)初始配置git ,git init git ...
- 【Asp.net】 七大内置对象
本文主要分析Asp.net的7大内置对象. 利用提供的内置对象可以实现页面之间的数据传递和一些特定的功能,如数据输出,页面重定向等.5个核心常用内置对象分别是Application,Session, ...
- 文件下载(download) 前后台备注自用
1.后台 1.1 ResponseBean 返回封装的格式 @Data @Accessors(chain = true) public class ResponseBean { private Str ...
- char、vchar、nvarchar 的区别
Unicode字符集就是为了解决字符集这种不兼容的问题而产生的,它所有的字符都用两个字节表示,即英文字符也是用两个字节表示 如果还为了这个纠结,就直接看看后面的解说,做决定吧. 一般如果用到中文或者其 ...
- 洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 使用四种算法
洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 水题一道…… 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. ...
- C#面向对象详解
//封装就是将数据或函数等集合在一个个的单元中,我们称之为类,被封装的对象通常被称为抽象数据类型, //封装的意义在于保护或防止代码被我们无意中破坏, //封装既可以封装成员变量,又可以封装成员方法, ...