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 ...
随机推荐
- Linux运维--12.手动部署Rabbit集群
1.安装rabbit组件 10.100.2.51 controller1 10.100.2.52 controller2 10.100.2.53 controller3 #每个节点 yum insta ...
- springBoot2.x启动项目报java.sql.SQLNonTransientConnectionException
将项目从springBoot1.x升级到springBoot2.x,启动报错: java.sql.SQLNonTransientConnectionException: Cannot load con ...
- git系列之---将本地的项目添加到码云仓库
1.前情: 本地写的 Demo 传到码云上面进行维护. 2.操作步骤: git init 将本地文件初始化为git 仓库,文件件会多一个 .git 文件夹[版本库]: git add . 或者 ...
- Javascript 基础学习(五)js 的运算符
通过运算符可以对一个或多个值进行运算,并且一定有运算结果返回 算数运算符 算数运算符包括相加(+).相减(-).相乘(*).相除(/).取模(%).任何值与字符串相加都会转换为字符串,做的是字符串 ...
- 关于elementui的table组件单元格的内容自定义写法
------------恢复内容开始------------ 记录老哥的写法 columns是表格的配置文件 在表格渲染的时候通过renderTableCell传入表格的row以及配置文件中的rend ...
- nginx配置访问https[自签版]
通过openssl生成证书 (1)设置server.key,这里需要设置两遍密码: openssl genrsa -des3 -out server.key 1024 (2)参数设置,首先这里需要输入 ...
- SynchronizationContext(同步上下文)综述
>>返回<C# 并发编程> 1. 概述 2. 同步上下文 的必要性 2.1. ISynchronizeInvoke 的诞生 2.2. SynchronizationContex ...
- 使用Teigha.net读取CAD的常用功能模块
Teigha中实体旋转 代码: using (var trans = database.TransactionManager.StartTransaction()) { Entity ent = tr ...
- 小白的linux笔记4:几种共享文件方式的速度测试——SFTP(SSH)/FTP/SMB
测试一下各个协议的速度,用一个7205M的centos的ISO文件上传下载.5Gwifi连接时,本地SSD(Y7000)对服务器的HDD: smb download 23M/s(资源管理器) smb ...
- 学习R语言的一点小心得
1.目前R 语言处于入门阶段吧,能够执行一些简单的模型了,还是有收获的. 但是在跑模型的时候经常遇到各种各样的错误,最常见的错误就是数据带入模型之后,数据的类型不对,因此模型跑不下去,因此说,利用he ...