Adding Powers

Suppose you are performing the following algorithm. There is an array v1v1v1,v2v2v2,…,vnvnvn filled with zeroes at start. The following operation is applied to the array several times — at i−thi-thi−th step (000-indexed) you can:

  • either choose position pos (1≤pos≤n)(1≤pos≤n)(1≤pos≤n) and increase vposv_{pos}vpos​ by kikiki;
  • 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 vvv equal to the given array a (vj=ajvj=ajvj=aj for each jjj) after some step?

Input

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

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

The second line contains nnn integers a1,a2,…,an(0≤ai≤1016)a1,a2,…,an (0≤ai≤10^{16})a1,a2,…,an(0≤ai≤1016) — the array you’d like to achieve.

Output

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

Example
input
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
YES
YES
NO
NO
YES

Note

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

In the second test case, you can add k0k0k0 to v1v1v1 and stop the algorithm.

In the third test case, you can’t make two 111 in the array vvv.

In the fifth test case, you can skip 909^090 and 919^191, then add 929^292 and 939^393 to v3v3v3, skip 949^494 and finally, add 959^595 to v2v2v2.

思路

题意:给出一个数列,数字k,数列中的每个数字能否由k的n次方加成,且每个次方只能用一次。很明显将每个数字的k进制表示出来,然后判断同一位次上的数字之和是否 ≤1≤1≤1,这样就可以了,用一个数组统计每一个位次上的和。

代码

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mx=2e5+10;
int s[100];
ll t,n,k;
ll a[mx];int main()
{scanf("%d",&t);while(t--){bool flag=false;memset(s,0,sizeof(s));scanf("%lld%lld",&n,&k);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);for(int i=1;i<=n;i++){int j=0;while(a[i])//统计每一个数字的k进制{s[j]+=a[i]%k;//加上同一位次的j++;a[i]/=k;}}for(int i=0;i<100;i++)if(s[i]>1)//只要有超过一次的就不能了{flag=true;break;}if(flag)printf("NO\n");elseprintf("YES\n");}return 0;
}

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. C. Adding Powers

    链接:https://codeforces.ml/contest/1312/problem/C Suppose you are performing the following algorithm. ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

最新文章

  1. 如何利用离散Hopfield神经网络进行高校科研能力评价(2)
  2. hdu6989 (莫队+单调栈+ST表)
  3. Python创建简单的HTTP服务
  4. uplift model学习笔记
  5. 平板电脑硬件如何测试软件,先锋(Pioneer)G71平板电脑软件测试评测-ZOL中关村在线...
  6. mysql primary unique_MySQL中的INDEX,PRIMARY,UNIQUE,FULLTEXT之间的区别?
  7. MySQL事务隔离级别解密
  8. 设计模式Demo制作bug以及反思集锦
  9. 泛泰A870(高通APQ8064t 600 cpu) Mokee4.4.2(Android4.4) 图赏
  10. C4D Octane渲染器 学习笔记(二)
  11. 获取深户股市列表api_获取股票api
  12. Android Bugs——Error:java.lang.RuntimeException: Some file crunching failed, see logs for details
  13. Vue——构造内嵌登录二维码
  14. Kinect能掀起体感应用开发热潮吗?
  15. 软件测试需要掌握的技能
  16. 如何让谷歌浏览器支持迅雷下载
  17. ref,reactive toRaw
  18. 对服务器整体性能画像,青云科技发布新一代企业级云服务器e3 绘制云基础设施标准画像...
  19. Visp系列学习二:visp显示和visp_ros获取图像
  20. 中国有色金属行业投资机会与十四五运营战略规划报告2022-2027年

热门文章

  1. typora设置标题自动编号
  2. 量化交易入门,看这篇就够了
  3. win10 uwp 自定义控件初始化
  4. 如何轻松清除Google搜索记录
  5. React-native开发-Unrecognized font family ‘Ionicons’
  6. java 二进制转图片_Java如何把二进制数据转换成图片???
  7. 生物信息学研究生课程-1
  8. 如何练好嗓子 让声音变得浑厚
  9. confluent(Confluent Cloud)
  10. 短信验证码接口开发代码