-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddingpoers.java
More file actions
35 lines (33 loc) · 1.01 KB
/
addingpoers.java
File metadata and controls
35 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class addingpoers {
static int mod = (int) 1e9 + 7;
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0) {
int n = sc.nextInt(), k = sc.nextInt();
long[] arr = new long[n];
byte[] count=new byte[64];
for (int i = 0; i < n; i++) arr[i] = sc.nextLong();
boolean z=false;
for(int i=0;i<n;i++){
int c=0;
while(arr[i]!=0){
if(arr[i]%k>1)z=true;
if(arr[i]%k!=0)count[c]++;
if(count[c]>1)z=true;
c++;
arr[i]/=k;
}
if(z)break;
}
if(z)sb.append("NO\n");
else sb.append("YES\n");
}
System.out.println(sb);
}
}