CF1312C Adding Powers

首先可以转化为在第 \(i\) 次操作,可以选择不做,也可以选择把 \(pos\) 位置上的数减去 \(k^i\),问能否经过若干次操作把所有数字变成 \(0\)

然后由此可以想到 \(k\) 进制,把每个数分解,记分解完的第 \(i\)\(x_i\),那么根据题目要求 \(x_i\) 不能大于 \(1\),那么我们开个桶 \(cnt_i\) 表示所有数的 \(k\) 进制表示下第 \(i\) 位的和,然后扫一遍判断是否有大于 \(1\) 的。

#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int mod = 998244353;
// const int mod = 1e9 + 7;
struct mod_t {
  static int norm(int x) {
    return x + (x >> 31 & mod);
  }
  int x;
  mod_t() {  }
  mod_t(int v) : x(v) {  }
  mod_t(ll v) : x(v) {  }
  mod_t(char v) : x(v) {  }
  mod_t operator +(const mod_t &rhs) const {
    return norm(x + rhs.x - mod);
  }
  mod_t operator -(const mod_t &rhs) const {
    return norm(x - rhs.x);
  }
  mod_t operator *(const mod_t &rhs) const {
    return (ll) x * rhs.x % mod;
  }
};
const int MAXN = 60;
int n, k, cnt[MAXN];
ll a[MAXN];
inline void work() {
  n = rdint();
  k = rdll();
  ms(cnt);
  For(i, n) {
    a[i] = rdll();
  }
  For(i, n) {
    for(reg int j = 0; a[i]; ++j, a[i] /= k) {
      cnt[j] += a[i] % k;
    }
  }
  For0(i, MAXN) {
    if(cnt[i] > 1) {
      puts("NO");
      return;
    }
  }
  puts("YES");
}
int main() {
  // freopen("input.txt", "r", stdin);
  int _ = rdint();
  while(_--) {
    work();
  }
  return 0;
}
posted @ 2020-09-12 22:47  Nylch  阅读(67)  评论(0编辑  收藏  举报