Topic links: https://codeforces.com/contest/1312
Subject to the effect:
An array can perform any of the operations, so that it becomes the target array.
For the first i th operation, we can give, or to any one of the array elements plus k ^ i
idea:
We can easily find a number = k ^ x + k ^ y + k ^ z + ... (x! = Y! = Z)
This form much like our binary so we can know is to put this number into a k-ary, then you can only use once every
#pragma GCC optimize(3,"Ofast","inline")//O3优化 #pragma GCC optimize(2)//O2优化 #include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #include <cmath> #include <sstream> #include <iostream> #include <cstring> #define LL long long #define ls nod<<1 #define rs (nod<<1)+1 #define pii pair<int,int> #define mp make_pair #define pb push_back #define INF 0x3f3f3f3f #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) const double eps = 1e-10; const int maxn = 2e6 + 10; const LL mod = 1e9 + 7; int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;} using namespace std; int screws [ 100 ]; int main () { ios::sync_with_stdio(0); int T; cin >> T; while (T--) { memset(vis,0,sizeof(vis)); int n; LL k; cin >> n >> k; bool fl = false; for (int i = 1;i <= n;i++) { int cnt = 0; LL a; cin >> a; if (a == 0 || fl) continue; while (1) { if (a % k == 1) { if (!vis[cnt]) view [cnt] = 1 ; else { fl = true; break; } } else if (a % k > 1) { fl = true; break; } a = a / k; cnt++; if (a == 0) break; } } if (fl) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }