C

题意

定义p-binary为2^x+p

现在给你一个数x,和一个p。

问你最少用多少个p-binary能构造出x,如果没有输出-1

题解

转化为:

x = 2^x1 + 2^x2 + ... + 2^xn + n*p

首先我们知道任何数都能用二进制表示,如果p=0的话,肯定是有解的。那么答案最少都是x的2进制1的个数。

另外什么情况无解呢,即x-n*p<0的时候肯定无解,可以更加有优化为x-n*p<n的时候无解。

答案实际上就是n,我们从小到大枚举n,然后check现在的2进制中1的个数是否小于等于n。

#include<bits/stdc++.h>
using namespace std; int Count(int x){
int number=0;
for(;x;x-=x&-x){
number++;
}
return number;
}
int main(){
int n,p,ans=0;
scanf("%d%d",&n,&p);
while(1){
n-=p;
ans++;
int cnt=Count(n);
if(ans>n){
cout<<"-1"<<endl;
return 0;
}
if(cnt<=ans){
cout<<ans<<endl;
return 0;
}
}
}

  D

You are given n positive integers a1,…,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk.

In the sample case, the suitable pairs are:

a1⋅a4=8=2^3;
a1⋅a6=1=1^3;
a2⋅a3=27=3^3;
a3⋅a5=216=6^3;
a4⋅a6=8=2^3.

题意

题目这么短,我就偷懒不翻译了吧。。

题解

首先我们质因数分解后,如果两个数的质因数分解后的每个数的因子个数都是k的倍数,那么就说明有解。

于是我们先对每个数质因数分解一下,然后再用一个vector去找一下配对的那一个是哪个。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,k;
int a[maxn];
map<vector<pair<int,int> >,int>H;
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
long long ans = 0;
for(int i=0;i<n;i++){
string tmp="";
vector<pair<int,int> >fac;
for(int now=2;now*now<=a[i];now++){
int number=0;
while(a[i]%now==0){
a[i]/=now;
number+=1;
}
if(number%k)
fac.push_back(make_pair(now,number%k));
}
if(a[i]>1)fac.push_back(make_pair(a[i],1%k));
vector<pair<int,int> >fac2;
for(int j=0;j<fac.size();j++){
fac2.push_back(make_pair(fac[j].first,k-fac[j].second));
}
ans+=H[fac2];
H[fac]++;///类似前缀的方式可以避免重复选到以下情况【ai,aj】【aj,ai】;
}
cout<<ans<<endl;
}

 

codeforces 596的更多相关文章

  1. codeforces 596 C. p-binary

    题意:给你一个n和一个p,让你用 (2k+p)进制来表示n,找出用最少的(2k+p)来表示n. 分析:首先我们看到2k,首先下想到二进制,我们可以我们列出式子,也就是 (2x1 + p)+(2x2 + ...

  2. 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. 题解:很显然只有 \( ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round 596 题解

    万幸的是终于碰上了一场上分好场. 不幸的是一开始差点不会 A. 万幸的是想了个不那么稳的结论过了 pretest. 不幸的是罚时很高,而且慌得一比. 万幸的是然后半个小时内把 B 和 C 码了. 不幸 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 刷题49. Group Anagrams

    一.题目说明 题目是49. Group Anagrams,给定一列字符串,求同源词(包含相同字母的此)的集合.题目难度是Medium. 二.我的做法 题目简单,就不多说,直接上代码: class So ...

  2. [题解] CF932E Team Work

    CF932E Team Work 你现在手里有\(n\)个人,你要选出若干个人来搞事情(不能不选),其中选择\(x\)个人出来的代价是\(x^k\),问所有方案的代价总和. 数据范围:\(1\le n ...

  3. 转载:HTTP 请求头中的 X-Forwarded-For,X-Real-IP

    转载:https://www.cnblogs.com/diaosir/p/6890825.html  X-Forwarded-For 在使用nginx做反向代理时,我们为了记录整个的代理过程,我们往往 ...

  4. MFC 实现CTreeCtrl单选

    void CDepartmenManager::SetUncheck(HTREEITEM hTree) { if (!hTree){ return; } m_DePartmentView.SetChe ...

  5. Kubernetes-基于helm安装部署高可用的Redis及其形态探索

    首先是一些关于redis的介绍和其在K8S上的安装过程:https://www.kubernetes.org.cn/3974.html 1.1部署形态 通过上述地址的教程,可以完成redis 的安装和 ...

  6. Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx”

    今天在调程序的时候遇到这个问题 解决办法:将安装在MDK下面的文件属性由只读去掉: 成功!可以下载.

  7. Windows环境安装与搭建node.js环境

    参考文章:https://www.cnblogs.com/zhouyu2017/p/6485265.html 一.下载node.js,直接下一步至安装完成.https://nodejs.org/en/ ...

  8. C语言-存储类&作用域&生命周期&链接属性

    1.概念解析(1)存储类 a.存储类就是存储类型,也就是描述C语言变量在何种地方存储. b.内存有多种管理办法:栈.堆.数据段.bss段..text段......一个变量的存储类属性就是描述这个变量存 ...

  9. 数据库连接池DBCP的使用

    一.直接使用代码链接(一般企业开发不用这种方式) 1.导入JAR 把jar包拷贝到lib文件夹里面然后右击 build path一下 2.建一个jdbc.proprtties文件 driverClas ...

  10. Java UDP发送与接收

    IP地址?端口号?主机名? 什么是Socket? 什么是UDP? 什么是TCP? UDP和TCP区别? 以上问题请自行百度,有标准解释,此处不再赘述,直接上干货! 实例: 发送端: public cl ...