-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddingPowers.java
More file actions
50 lines (48 loc) · 1.25 KB
/
AddingPowers.java
File metadata and controls
50 lines (48 loc) · 1.25 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AddingPowers {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long[] array = new long[30]; String[] temp; int num; int k;
boolean gotone; boolean possible;
for (int i = 0; i < N; i++)
{
temp = br.readLine().split(" ");
num = Integer.parseInt(temp[0]); k = Integer.parseInt(temp[1]);
temp = br.readLine().split(" ");
for (int a = 0; a < num; a++)
array[a] = Long.parseLong(temp[a]);
possible = true;
outer: for (int a = 0; a < 55; a++) //upper bound 55
{
gotone = false;
for (int b = 0; b < num; b++)
{
if (array[b]%k != 0)
{
if (array[b]%k != 1)
{
possible = false;
break outer;
}
if (gotone == false)
gotone = true;
else
{
possible = false;
break outer;
}
}
array[b] = array[b]/k;
}
}
if (possible)
System.out.println("YES");
else
System.out.println("NO");
}
}
}