-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem83.java
58 lines (51 loc) · 1.16 KB
/
Problem83.java
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
51
52
53
54
55
56
57
58
package dimikOJ;
import java.util.Scanner;
public class Problem83 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while (T < 1) {
T = input.nextInt();
}
input.nextLine();
long[] n = new long[T];
for (int i = 0; i < n.length; i++) {
long temp = input.nextLong();
int digitCount = countDigit(temp);
while (digitCount < 1 || digitCount > 1100 || temp < 1) {
temp = input.nextLong();
digitCount = countDigit(temp);
}
n[i] = temp;
}
input.close();
for (int i = 0; i < n.length; i++) {
long N = n[i];
int K = 0;
boolean notPower = true;
long output = (long) Math.pow(2, K);
while (output <= N) {
if (output == N) {
notPower = false;
System.out.println("It's a power of 2");
break;
} else {
K++;
output = (long) Math.pow(2, K);
}
}
if (notPower) {
System.out.println("Not a power of 2");
}
}
}
static int countDigit(long n) {
int count = 0;
while (n != 0) {
n = n / 10;
++count;
}
return count;
}
}