乘方相加
AcWing 3727
https://www.acwing.com/problem/content/3730/
10进制数转k进制数 每个位上最大为1 超过则不能转化
代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100;
int s[N];
int main()
{
int T;
cin >> T;
while (T--)
{
int n,k;
cin >> n >> k;
memset(s, 0, sizeof s);
while (n--)
{
LL x;
cin >> x;
for (int j = 0; x ; j ++,x /= k)//10进制转k进制
s[j] += x % k;
}
bool flag = false;
for (int i = 0; i < N; i ++ )
if (s[i] > 1) flag = true;
if (flag) puts("NO");
else puts("YES");
}
return 0;
}