链接:https://codeforces.ml/contest/1312/problem/C

Suppose you are performing the following algorithm. There is an array v1,v2,…,vnv1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at ii-th step (00-indexed) you can:

  • either choose position pospos (1≤pos≤n1≤pos≤n) and increase vposvpos by kiki;
  • or not choose any position and skip this step.

You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array vv equal to the given array aa (vj=ajvj=aj for each jj) after some step?

Input

The first line contains one integer TT (1≤T≤10001≤T≤1000) — the number of test cases. Next 2T2T lines contain test cases — two lines per test case.

The first line of each test case contains two integers nn and kk (1≤n≤301≤n≤30, 2≤k≤1002≤k≤100) — the size of arrays vv and aa and value kk used in the algorithm.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10160≤ai≤1016) — the array you'd like to achieve.

Output

For each test case print YES (case insensitive) if you can achieve the array aa after some step or NO (case insensitive) otherwise.

Example

input

Copy

5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810

output

Copy

YES
YES
NO
NO
YES

Note

In the first test case, you can stop the algorithm before the 00-th step, or don't choose any position several times and stop the algorithm.

In the second test case, you can add k0k0 to v1v1 and stop the algorithm.

In the third test case, you can't make two 11 in the array vv.

In the fifth test case, you can skip 9090 and 9191, then add 9292 and 9393 to v3v3, skip 9494 and finally, add 9595 to v2v2.

代码:

#include<bits/stdc++.h>
using namespace std;
long long t,n,k,p,s,ans;
long long a[101],v[101];
int main()
{cin>>t; while(t--){cin>>n>>k;s=n;ans=0;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);int flag=1;while(a[n]){ans=0;for(int i=1;i<=n;i++){if(a[i]%k==1&&ans==0){ans++;a[i]--;a[i]/=k;}else if(a[i]%k==1){flag=0;break;}else if(a[i]%k==0){a[i]/=k;}else{flag=0;break;}}if(flag==0)break; }if(flag==0)cout<<"NO"<<endl;elsecout<<"YES"<<endl;}
}

C. Adding Powers相关推荐

  1. CodeForces - 1312C Adding Powers(思维+位运算)

    题目链接:点击查看 题目大意:给出大小为 n 的一个数组 a 和一个数字 K,每个位置起始时为 0 ,现在从 i = 0 开始递增,我们能够进行如下操作: 选取 pos ∈ [ 1 , n ] 作为数 ...

  2. C .Adding Powers codeforces(位运算思维)

    outputstandard output Suppose you are performing the following algorithm. There is an array v1,v2,-, ...

  3. 【深入理解计算机系统】 一:数值表示与编码

    本课程内容来自于悉尼大学ELEC1601:introduction to the computer system 2.1. Binary Logic The digital electronic ci ...

  4. Educational codeforces round 83 div2C(类似进制转换,等比数列又一个性质)

    C. Adding Powers 原题目地址 题意: 给你一个目标数组,要你 对一个所有元素从0开始的数组 进行一种操作. 每一步可以对一个元素增加 k^i ( i 为每一步)( i 可以为0) 或者 ...

  5. android.util.AndroidRuntimeException: requestFeature() must be called before adding content

    问题 Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding co ...

  6. UVA 10515 - Powers Et Al.(数论)

    UVA 10515 - Powers Et Al. 题目链接 题意:求出m^n最后一位数 思路:因为m和n都非常大,直接算肯定是不行的,非常easy想到取最后一位来算,然后又非常easy想到最后一位不 ...

  7. R语言ggplot2可视化、在可视化区域中自定义添加多个大小不同矩形阴影区域、自定义配置大小不同矩形阴影区域的颜色(Adding multiple shadows/rectangles)

    R语言ggplot2可视化.在可视化区域中自定义添加多个大小不同矩形阴影区域.自定义配置大小不同矩形阴影区域的颜色(Adding multiple shadows/rectangles) 目录

  8. R语言在可视化图像中添加文本(Adding Text to plot)

    R语言在可视化图像中添加文本(Adding Text to plot) 创建一个好的可视化包括引导读者,使用图形讲述一个直观的故事.在某些情况下,这个故事可以以完全直观生动的方式呈现,而不需要添加文本 ...

  9. SAP WM中阶之存储类型上架策略I(Adding to existing stock)

    SAP WM中阶之存储类型上架策略I(Adding to existing stock) SAP WM模块里,有很多上架策略.Adding to existing stock是一种常用的上架策略.这种 ...

最新文章

  1. 什么??听说Python要凉!
  2. Spring boot 启动后执行特定的操作
  3. 137% YOLOv3加速、10倍搜索性能提升!这样的惊喜,最新版PaddleSlim有10个
  4. bzoj2744[HEOI2012]朋友圈
  5. 排除服务器简单系统故障方法,引导CD排除服务器故障方法有哪些?
  6. Ubuntu配置完全教程
  7. 在容器上构建持续部署及最佳实践初探
  8. 无法装载文件或者汇编的AjaxControlToolkit
  9. java自定义classloader_java自定义ClassLoader加载指定的class文件操作
  10. 几人同行时步伐总是整齐
  11. 词云中去重复的词_今天从零教你开始利用Python打造词云图!
  12. Markdown转pdf分页
  13. QT写的U盘批量复制小工具
  14. Ubuntu虚拟机如何与主机复制粘贴?
  15. 在CATIA中实现道路缓和曲线的方法
  16. wps下一页 很好玩!wps中怎么插入欧姆符号
  17. C - One-dimensional Japanese Crossword CodeForces - 721A
  18. 【洛谷 P3809】 【后缀数组】【模板】后缀排序
  19. 网络安全守护神(SOC)
  20. CAD想画得快,你需要看看我的吐槽

热门文章

  1. http以及HttpServletRequest详解
  2. 通过C实现2018以内的闰年判断
  3. Word字号与磅值之间的关系
  4. php一库多站,杰奇CMS小说系统 一库多站完整实现教程
  5. MySQL 服务正在启动 MySQL 服务无法启动解决办法
  6. 基于matlab仿真相控天线阵列在波束成形MIMO-OFDM系统中的使用(附源码)
  7. Mac安装鸿蒙系统,搭建MAC系统下的Wi-Fi loT Hi3861鸿蒙开发环境
  8. 文献阅读 | 基于ATAC-seq数据的SNV与indels的发现
  9. window10 右键个性化和设置无法打开,提示关联问题
  10. 带通 带阻滤波器 幅频响应_微波介质陶瓷滤波器简介